Creates fake JSON files from a JSON schema
Project Links
Meta
Author: ghandic
Requires Python: >=3.8
Classifiers
Programming Language
- Python :: 3
License
- OSI Approved :: MIT License
Operating System
- OS Independent
jsf
Use jsf along with fake data generators to provide consistent and meaningful fake data for your system.
Main Features
- Provides out of the box data generation from any JSON schema ๐ฆ
- Extendable custom data providers using any lambda functions ๐
- Multi level state for dependant data (eg multiple objects sharing value, such as children with same surname) ๐ค
- Inbuilt validation of fake JSON produced โ
- In memory conversion from JSON Schema to Pydantic Models with generated examples ๐คฏ
- Seamless integration with FastAPI ๐
Installation
$ pip install jsf
---> 100%
Usage
Basic ๐
from jsf import JSF
faker = JSF(
{
"type": "object",
"properties": {
"name": {"type": "string", "$provider": "faker.name"},
"email": {"type": "string", "$provider": "faker.email"},
},
"required": ["name", "email"],
}
)
fake_json = faker.generate()
Results in ...
{
'name': 'Jesse Phillips',
'email': 'xroberson@hotmail.com'
}
From JSON file ๐
from jsf import JSF
faker = JSF.from_json("demo-schema.json")
fake_json = faker.generate()
Or run straight from the commandline...
Native install
pip install jsf[cli]
jsf --schema jsf/tests/data/custom.json --instance wow.json
Docker
docker run -v $PWD:/data challisa/jsf jsf --schema /data/custom.json --instance /data/example.json
FastAPI Integration ๐
Create a file main.py with:
from jsf import JSF
from fastapi import FastAPI
app = FastAPI(docs_url="/")
generator = JSF.from_json("custom.json")
@app.get("/generate", response_model=generator.pydantic())
def read_root():
return generator.generate()
Run the server with:
$ uvicorn main:app --reload
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [28720]
INFO: Started server process [28722]
INFO: Waiting for application startup.
INFO: Application startup complete.
Navigate to http://127.0.0.1:8000 and check out your endpoint. Notice the following are all automatically created:
- Schema with descriptions and examples
- Example response
- Data generation by clicking "try it out"

Partially supported features
- string
contentMediaType- only a subset of these are supported, however they can be expanded within this file
Credits
- This repository is a Python port of json-schema-faker with some minor differences in implementation.
License
0.11.2
Mar 26, 2024
0.11.1
Mar 25, 2024
0.11.0
Mar 10, 2024
0.10.0
Jan 28, 2024
0.9.0
Dec 04, 2023
0.8.0
Aug 21, 2023
0.7.1
Jan 20, 2023
0.7.0
Jan 08, 2023
0.6.0
Jan 08, 2023
0.5.4
Jan 07, 2023
0.5.3
Jan 07, 2023
0.5.2
Jan 02, 2023
0.5.1
Jan 02, 2023
0.5.0
Dec 31, 2022
0.4.0
Jun 30, 2022
0.3.2
May 04, 2021
0.3.1
May 03, 2021
0.3.0
May 03, 2021
0.2.0
Apr 14, 2021
0.1.1
Apr 11, 2021
0.1.0
Apr 08, 2021