All Projects → ueg1990 → faker-schema

ueg1990 / faker-schema

Licence: MIT license
Generate fake data using joke2k's faker and your own schema

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to faker-schema

Mimesis
Mimesis is a high-performance fake data generator for Python, which provides data for a variety of purposes in a variety of languages.
Stars: ✭ 3,439 (+3679.12%)
Mutual labels:  schema, faker
vue-example
Vue.js example application (server-side rendering, router, vuex store, form validation, i18n & l10n)
Stars: ✭ 62 (-31.87%)
Mutual labels:  schema
FakerDotNet
A .NET port of the Ruby faker gem
Stars: ✭ 15 (-83.52%)
Mutual labels:  faker
schema2ldif
Schema 2 ldif : tool to convert .schema to .ldif files and mange them live into an openldap server
Stars: ✭ 14 (-84.62%)
Mutual labels:  schema
felicity
Javascript object constructors and sample data based on Joi schema.
Stars: ✭ 107 (+17.58%)
Mutual labels:  schema
jedi-faker
Faker extension for Star Wars junkie
Stars: ✭ 15 (-83.52%)
Mutual labels:  faker
react-aztec
🔥 Material UI based dynamic form component for React using JSON
Stars: ✭ 37 (-59.34%)
Mutual labels:  schema
pocket-cms
☁️ A pocket sized CMS written for nodejs
Stars: ✭ 13 (-85.71%)
Mutual labels:  schema
decoratex
No description or website provided.
Stars: ✭ 34 (-62.64%)
Mutual labels:  schema
hasura-sdk
Hasura Schema & Metadata Typescript SDK
Stars: ✭ 21 (-76.92%)
Mutual labels:  schema
soap-typescript
SOAP decorators for creating wsdl's and annotating services to provide metadata for node-soap
Stars: ✭ 20 (-78.02%)
Mutual labels:  schema
mongodb-schema
Infer a probabilistic schema for a MongoDB collection.
Stars: ✭ 106 (+16.48%)
Mutual labels:  schema
bypass
↪️ Bypass for PHP creates a custom HTTP Server to return predefined responses to client requests. Useful for tests with Pest PHP or PHPUnit.
Stars: ✭ 98 (+7.69%)
Mutual labels:  faker
apollobank
A full stack GraphQL banking application using React, Node & TypeScript.
Stars: ✭ 203 (+123.08%)
Mutual labels:  faker
JetBrains-scheme
JetBrains主题,更完美的高亮。支持 IntelliJ IDEA、phpstorm、goland、webstorm
Stars: ✭ 25 (-72.53%)
Mutual labels:  schema
swagger-faker
Generate mocker services automatically through Swagger or OpenAPI.
Stars: ✭ 26 (-71.43%)
Mutual labels:  faker
godmt
Tool that can parse Go files into an abstract syntax tree and translate it to several programming languages.
Stars: ✭ 42 (-53.85%)
Mutual labels:  schema
mapper
Map tarantool tuples to php objects.
Stars: ✭ 68 (-25.27%)
Mutual labels:  schema
formily
Simple, lightweight, and flexible schema-based form for Vue.js
Stars: ✭ 23 (-74.73%)
Mutual labels:  schema
really-rich-results
RRR makes structured data for WordPress really rich, and really easy.
Stars: ✭ 21 (-76.92%)
Mutual labels:  schema

faker-schema

Generate fake data using joke2k's faker and your own schema.

Installation

pip install faker-schema

Usage

Getting started

from faker_schema.faker_schema import FakerSchema

schema = {'employee_id': 'uuid4', 'employee_name': 'name', 'employee address': 'address',
          'email_address': 'email'}
faker = FakerSchema()
data = faker.generate_fake(schema)
print(data)
# {'employee_id': '956f0cf3-a954-5bff-0aaf-ee0e1b7e1e1b', 'employee_name': 'Adam Wells',
#  'employee address': '189 Kyle Springs Suite 110\nNorth Robin, OR 73512',
#  'email_address': '[email protected]'}

This library is dependent on faker for available schema types. Faker provides a wide variety of data types via providers. For a list of available providers, checkout Providers and Community Providers

Once you know what types you want to generate your fake data, you can start defining your own schema

Defining your schema

The expected schema is a dictionary, where the keys are field names and the values are the types of the fields. The schema dictionay can have nested dictionaries and lists too.

Loading schemas

faker-schema currently provides two ways of loading your schema:

  • JSON file
  • JSON string
import json

from faker_schema.faker_schema import FakerSchema
from faker_schema.schema_loader import load_json_from_file, load_json_from_string

schema = load_json_from_file('path_to_json_file')
faker = FakerSchema()
data = faker.generate_fake(schema)

# OR

json_string = '{"employee_id"": "uuid4", "employee_name": "name"", "employee address":
                "address", "email_address": "email"}'

schema = load_json_from_string(json_string)
faker = FakerSchema()
data = faker.generate_fake(schema)

You can define your own way of loading a schema, convert it to a Python dictionary and pass it to the FakerSchema instance. The aim was to de-couple schema loading/generation from fake data generation. If you want to contribute more schema loading techniques, please open a GitHub issue or send a pull request.

Using different locales

The Faker library provides a list of different locales. You can choose your required locale from that list and provide it to the FakerSchema instance

from faker_schema.faker_schema import FakerSchema

schema = {'employee_id': 'uuid4', 'employee_name': 'name', 'employee address': 'address',
          'email_address': 'email'}
faker = FakerSchema(locale='it_IT')
data = faker.generate_fake(schema)
print(data)
# {'employee_id': '47f8bb04-fc05-25c9-73cc-e8a22f29ee4e', 'employee_name': 'Caio Negri',
#  'employee address': 'Stretto Davis 34\nDamico lido, 54802 Vibo Valentia (TR)',
#  'email_address': '[email protected]'}

More Schema Examples

Nested Dictionary

from faker_schema.faker_schema import FakerSchema

schema = {'EmployeeInfo': {'ID': 'uuid4', 'Name': 'name', 'Contact': {'Email': 'email',
          'Phone Number': 'phone_number'}, 'Location': {'Country Code': 'country_code',
          'City': 'city', 'Country': 'country', 'Postal Code': 'postalcode',
          'Address': 'street_address'}}}
faker = FakerSchema()
data = faker.generate_fake(schema)
# {'EmployeeInfo': {'ID': '0751f889-0d83-d05f-4eeb-16f575c6b4a3', 'Name': 'Stacey Williams',
#  'Contact': {'Email':'[email protected]', 'Phone Number': '1-077-859-6393'},
#  'Location': {'Country Code': 'IE', 'City': 'Dyermouth', 'Country':
#  'United States Minor Outlying Islands', 'Postal Code': '84239',
#  'Address': '94806 Joseph Plaza Apt. 783'}}}

Nested List

from faker_schema.faker_schema import FakerSchema

schema = {'Employer': 'name', 'EmployeList': [{'Name': 'name'}, {'Name': 'name'},
          {'Name': 'name'}]}
faker = FakerSchema()
data = faker.generate_fake(schema)
# {'Employer': 'Faith Knapp', 'EmployeList': [{'Name': 'Douglas Bailey'},
# {'Name': 'Karen Rivera'}, {'Name': 'Linda Vance MD'}]}

Generating a certain number of fake data from given schema

from faker_schema.faker_schema import FakerSchema

schema = {'employee_id': 'uuid4', 'employee_name': 'name', 'employee address': 'address',
          'email_address': 'email'}
faker = FakerSchema()
data = faker.generate_fake(schema, iterations=4)
print(data)
# [{'employee_id': 'e07a7964-9636-bca6-2a58-4a69ac126dc5', 'employee_name':
# 'Charlene Blankenship', 'employee address': '0431 Edward Mountains Suite 697\nPort Douglas,
# TX 96239-7277', 'email_address': '[email protected]'}, {'employee_id':
# '42b02262-3e0c-cf40-8257-4a0af122dddb', 'employee_name': 'Cheryl Stevens',
# 'employee address': '48066 Eric Lake\nPhillipshire, MO 57224', 'email_address':
# '[email protected]'}, {'employee_id': '41efbcc4-bb32-9260-b2b3-8fac29782e01',
# 'employee_name': 'Dennis Campbell', 'employee address':
# '52418 Diana Mills Suite 590\nEast Mackenzie, HI 16222', 'email_address':
# '[email protected]'}, {'employee_id': '80bf12ff-2f3a-6db6-f3a6-14cb50076a46',
# 'employee_name': 'Jimmy Avery', 'employee address':
# '6867 Eddie Forest Apt. 735\nBranditon, IL 32717', 'email_address': '[email protected]'}]

BYOP (Bring Your Own Provider)

If you are using a community provider or you created your own provider, you can use those with faker-schema as well. I will use the provider, faker_web as an example.

After installing faker_web,

from faker import Faker
from faker_schema import FakerSchema
from faker_web import WebProvider

fake = Faker()
fake.add_provider(WebProvider)

faker = FakerSchema(faker=fake)
headers_schema = {'Content-Type': 'content_type', 'Server': 'server_token'}
fake_headers = faker.generate_fake(headers_schema)
print(fake_headers)
# {'Content-Type': 'application/json', 'Server': 'Apache/2.0.51 (Ubuntu)'}

Development

Running tests

  • Using make
make test
  • Using nose
nosetests
  • Using nose with coverage
nosetests --with-coverage --cover-package=faker_schema --cover-erase -v --cover-html

Running flake8

  • Using make
make flake8
  • Using flake8
flake8 --max-line-length 99 faker_schema/ tests/

Author

Usman Ehtesham Gul (ueg1990) - [email protected]

Contribute

If you want to add any new features, or improve existing one or if you find bugs, please open a GitHub issue or feel free to send a pull request. If you have any questions or need help/mentoring with contributions, feel free to contact me via email

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].