Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add from_typed_dict schema #1579

Open
sobolevn opened this issue Jul 7, 2024 · 5 comments
Open

Add from_typed_dict schema #1579

sobolevn opened this issue Jul 7, 2024 · 5 comments
Labels
feature Feature request

Comments

@sobolevn
Copy link
Collaborator

sobolevn commented Jul 7, 2024

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:

  • Generate password as a text, with no modifications
  • Generate email with a given modification
@sobolevn sobolevn added the feature Feature request label Jul 7, 2024
@lk-geimfari
Copy link
Owner

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

@lk-geimfari
Copy link
Owner

lk-geimfari commented Jul 10, 2024

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

@lk-geimfari
Copy link
Owner

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

@sobolevn
Copy link
Collaborator Author

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

@lk-geimfari
Copy link
Owner

God, time has flown by so fast. I'm very busy at work and so I've never got round to doing it, but I really want to. I hope that at least this weekend I will be able to get it off the ground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request
Projects
None yet
Development

No branches or pull requests

2 participants