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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db3d009b9022375e7192d98ca8a0cb2ffedecab90cbc6a7612bf8ea03f5f7db1
|
|
| MD5 |
320fa45f562c0aad3b865ccb3f0e8f60
|
|
| BLAKE2b-256 |
1a8cdea5265a653d991a5b2193bcad60f2e350eb7e16381579ea5a69d9fd57bc
|
Provenance
The following attestation bundles were made for faker_jsonschema-1.0.0.tar.gz:
Publisher:
release.yml on anentropic/python-faker-jsonschema
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
faker_jsonschema-1.0.0.tar.gz -
Subject digest:
db3d009b9022375e7192d98ca8a0cb2ffedecab90cbc6a7612bf8ea03f5f7db1 - Sigstore transparency entry: 1057498008
- Sigstore integration time:
-
Permalink:
anentropic/python-faker-jsonschema@a5a16f6b669a4c4eece876d509a032c24bd50336 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/anentropic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a5a16f6b669a4c4eece876d509a032c24bd50336 -
Trigger Event:
push
-
Statement type:
File details
Details for the file faker_jsonschema-1.0.0-py3-none-any.whl.
File metadata
- Download URL: faker_jsonschema-1.0.0-py3-none-any.whl
- Upload date:
- Size: 32.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44438e8cd81f3826278027b7bfa1f3bb8f76b17da8c7e55a9723bc785b14a051
|
|
| MD5 |
b5042880218f7d06552b3388221f55c3
|
|
| BLAKE2b-256 |
4d6e1331a4a77d2829cbead07bf2c35f9d9f92dbec9b01cf46be47241151958f
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
faker_jsonschema-1.0.0-py3-none-any.whl -
Subject digest:
44438e8cd81f3826278027b7bfa1f3bb8f76b17da8c7e55a9723bc785b14a051 - Sigstore transparency entry: 1057498009
- Sigstore integration time:
-
Permalink:
anentropic/python-faker-jsonschema@a5a16f6b669a4c4eece876d509a032c24bd50336 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/anentropic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a5a16f6b669a4c4eece876d509a032c24bd50336 -
Trigger Event:
push
-
Statement type: