Skip to main content

jsf

Coverage Docs PyPI Latest Release
License Code style: black

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"

Example Swagger UI - Page 1 Example Swagger UI - Page 2 Example Swagger UI - Page 3 Example Swagger UI - Page 4

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

Metadata

Release files for jsf 0.11.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsf 0.11.2
File Size Uploaded
jsf-0.11.2.tar.gz 29.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jsf 0.11.2
File Interpreter ABI Platform
jsf-0.11.2-py3-none-any.whl Python 3 none any Details

Total release size: 79.2 kB

Release files / jsf-0.11.2.tar.gz

Download URL jsf-0.11.2.tar.gz
Size 29.8 kB
Tags Source
SHA-256 checksum
How to use checksums
07055b363281d38ce871a9256a00587d8472802c5108721a7fe5884465104b5d
BLAKE2b-256 checksum
How to use checksums
8d34cf272dfe4277ce03b275bb9f5e99001b31db01b21c290fd262333c96e34a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Release files / jsf-0.11.2-py3-none-any.whl

Download URL jsf-0.11.2-py3-none-any.whl
Size 49.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b4472c8c2d776eb3e0bb08368caa6ae0ead7ea78b20653facc07b6d93768612c
BLAKE2b-256 checksum
How to use checksums
0aae7435288ab8b3059823afa48508ddf658c27d96deb8a978498103ccd71ca8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.11.2 This release

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page