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.0.tar.gz (144.9 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.0-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: faker_jsonschema-1.0.0.tar.gz
  • Upload date:
  • Size: 144.9 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.0.tar.gz
Algorithm Hash digest
SHA256 db3d009b9022375e7192d98ca8a0cb2ffedecab90cbc6a7612bf8ea03f5f7db1
MD5 320fa45f562c0aad3b865ccb3f0e8f60
BLAKE2b-256 1a8cdea5265a653d991a5b2193bcad60f2e350eb7e16381579ea5a69d9fd57bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for faker_jsonschema-1.0.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for faker_jsonschema-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44438e8cd81f3826278027b7bfa1f3bb8f76b17da8c7e55a9723bc785b14a051
MD5 b5042880218f7d06552b3388221f55c3
BLAKE2b-256 4d6e1331a4a77d2829cbead07bf2c35f9d9f92dbec9b01cf46be47241151958f

See more details on using hashes here.

Provenance

The following attestation bundles were made for faker_jsonschema-1.0.0-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