Generating data by schema.
See original GitHub issueWe have implemented very primitive generator by schema:
from mimesis.schema import Schema
from mimesis import constants as c
schema = Schema(locale=c.EN)
# We will use format 'provider.method'
# Param 'schema' should be dict or path to json file.
result = schema.load(schema={
'username': 'personal.username',
'password': 'personal.password',
'full_name': 'datetime.full_name',
}).create()
But is not better solutions. @sobolevn suggest much better solutions using Lazy objects`, which looks like that:
>>> from custom.utils import format_phone
>>> from mimesis.schema import Schema, fields
>>> schema = Schema('en')
>>> schema.load(schema={
... "id": fields.cryptographic.uuid(version=4),
... "name": fields.personal.full_name(gender='female'),
... "version": fields.development.version(semantic=True),
... "phone": format_phone(fields.personal.phone),
... }).create(iterations=2)
I like second solution too.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:19 (13 by maintainers)
Top Results From Across the Web
Database Data Generator | DbSchema
Generate Random Data for MySql, PostgreSQL, Redshift, Cassandra, MSSql, Oracle, MariaDb and all relational and NoSQL databases.
Read more >Three Best Tools For Generating Fake Data | by Mala Deep
Here I will share the top 3 DIY dataset generators. 1. Mockaroo. Mockaroo Schema UI. Screenshot from ...
Read more >Mockaroo - Random Data Generator and API Mocking Tool ...
A free test data generator and API mocking tool - Mockaroo lets you create custom CSV, JSON, SQL, and Excel datasets to test...
Read more >Free Resources for Generating Realistic Fake Data
Free Resources for Generating Realistic Fake Data · (1) Faker · (2) Mockaroo · (3) GenerateData · (4) JSON Schema Faker · (5)...
Read more >Schema Generator
The Schema Generator processor generates a schema based on the structure of a record and writes the schema into a record header attribute....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Sure!
I don’t like current implementation. It breaks one major rule: “everything is an object”. Our fields right now are not objects in general case. They are strings.
So it could break a lot of things for the end user. Imagine a user has some sort of logic to reformat phone numbers to his specific needs. Like:
reformat_phone(value). How is it possible with the current implementation? Or any other functions/classes/etc which wraps values.What do I suggest?
Lazy objects (or generator)
In my opinion, we should create
LazyFieldwrapper to wrap any other existing field. And a specialfieldscontainer with all the existing fields wrapped intoLazyField. So, how would it work?On each iteration lazy objects (or generator) generates new value. User has all the control, code is more pythonic.
Considerations
Do you have any ideas? Am I missing something?