lk-geimfari / mimesis

Mimesis is a robust data generator for Python that can produce a wide range of fake data in multiple languages.
https://mimesis.name
MIT License
4.36k stars 326 forks source link

Add `from_typed_dict` schema #1579

Open sobolevn opened 3 weeks ago

sobolevn commented 3 weeks ago

Let's say I have this typed dict:

class User(TypedDict):
    email: str
    password: str

I would love to just pass this metadata to mimesis to get my random data without any code duplication. Example of API that I am thinking of:

mf = Field(locale=Locale.RU)
schema = Schema(iterations=1, typed_dict_provider=User, schema=lambda: {
    # Customization is still fine:
    'email': mf(
        'person.email',
        domains=settings.TRUSTED_DOMAINS,
    ),
})

So, this will:

lk-geimfari commented 2 weeks ago

This feature seems to be very useful. It would be great to have such a feature in Mimesis.

lk-geimfari commented 2 weeks ago

I think I may try to work on it this weekend.

lk-geimfari commented 2 weeks ago

I think the difficulty here can only be with nested entities.

sobolevn commented 2 weeks ago

See https://polyfactory.litestar.dev/reference/factories/typed_dict_factory.html