Skip to main content

Generate fake data matching a JSON schema with Faker.

Project description

faker-jsonschema

[ Docs ]

faker-jsonschema is a Faker provider that generates random data conforming to a JSON Schema.

Pass any JSON Schema dict to faker.from_jsonschema() and get back a valid, randomly generated value.

1800+ unit and PBT tests aiming to ensure correctness. Limitations of our strategies are acknowledged in the docs.

Install

pip install faker-jsonschema
# or
uv add faker-jsonschema

Usage

from faker import Faker
from faker_jsonschema.provider import JSONSchemaProvider

fake = Faker()
fake.add_provider(JSONSchemaProvider)

schema = {
    "type": "object",
    "properties": {
        "name": {"type": "string"},
        "score": {"type": "integer", "minimum": 0, "maximum": 100},
        "tags": {"type": "array", "items": {"type": "string"}, "maxItems": 3},
    },
    "required": ["name", "score"],
}

print(fake.from_jsonschema(schema))
# {'name': 'Doctor pass describe matter.', 'score': 8}

See the full documentation here.

Acknowledgements

This project exists because I have used joke2k's Faker lib many times at work and find it an invaluable tool in tests.

JSON Schema has some property specs defined as regex in JS syntax. So we need a way to translate those into Python/PCRE syntax that we can execute. We have vendored a fork of the now unmaintained Zac-HD/js-regex lib for that purpose, which unlocked that feature for us.

And then we needed a way to generate random values that match such a regex, for this we make use of the brilliant Hypothesis Property-based testing library, which has a handy from_regex() generation strategy. We also have some PBT tests using Hypothesis for its intended purpose.

Contributing

See MAINTAINER.md for development setup, common tasks, and release instructions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

faker_jsonschema-1.0.0a1.tar.gz (137.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

faker_jsonschema-1.0.0a1-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

Details for the file faker_jsonschema-1.0.0a1.tar.gz.

File metadata

  • Download URL: faker_jsonschema-1.0.0a1.tar.gz
  • Upload date:
  • Size: 137.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for faker_jsonschema-1.0.0a1.tar.gz
Algorithm Hash digest
SHA256 5b1903632b5a37957fac95a1537d06da25f232ad098e648d13e2dbef9f92e614
MD5 f9ca98f98e8b0ec357960ba79247a6c5
BLAKE2b-256 0822ce4fd5c5260a469a074bfca0b4d8b9078de6e74c9ba2ff2f19f61ca12510

See more details on using hashes here.

Provenance

The following attestation bundles were made for faker_jsonschema-1.0.0a1.tar.gz:

Publisher: release.yml on anentropic/python-faker-jsonschema

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file faker_jsonschema-1.0.0a1-py3-none-any.whl.

File metadata

File hashes

Hashes for faker_jsonschema-1.0.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 e209c6eed21b8918a51695eb87f2ba25f135ba28a10f9754a5a412160b95d830
MD5 52fec4f15adff02f51d9c9f5325d82ab
BLAKE2b-256 536135cc16101f7c96376020dd61c5de7b8b54312c458c79b78ac2c0b0b2f27f

See more details on using hashes here.

Provenance

The following attestation bundles were made for faker_jsonschema-1.0.0a1-py3-none-any.whl:

Publisher: release.yml on anentropic/python-faker-jsonschema

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page