Skip to main content

Creates fake JSON files from a JSON schema

Project description

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

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

jsf-0.11.2.tar.gz (29.8 kB view details)

Uploaded Source

Built Distribution

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

jsf-0.11.2-py3-none-any.whl (49.3 kB view details)

Uploaded Python 3

File details

Details for the file jsf-0.11.2.tar.gz.

File metadata

  • Download URL: jsf-0.11.2.tar.gz
  • Upload date:
  • Size: 29.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for jsf-0.11.2.tar.gz
Algorithm Hash digest
SHA256 07055b363281d38ce871a9256a00587d8472802c5108721a7fe5884465104b5d
MD5 e59faa8668bc364be0d83fe7db63e05e
BLAKE2b-256 8d34cf272dfe4277ce03b275bb9f5e99001b31db01b21c290fd262333c96e34a

See more details on using hashes here.

File details

Details for the file jsf-0.11.2-py3-none-any.whl.

File metadata

  • Download URL: jsf-0.11.2-py3-none-any.whl
  • Upload date:
  • Size: 49.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.18

File hashes

Hashes for jsf-0.11.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b4472c8c2d776eb3e0bb08368caa6ae0ead7ea78b20653facc07b6d93768612c
MD5 1f7f01c3917c1c4490f017cf0b428f9c
BLAKE2b-256 0aae7435288ab8b3059823afa48508ddf658c27d96deb8a978498103ccd71ca8

See more details on using hashes here.

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