Giter Club home page Giter Club logo

jsf's Introduction

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': '[email protected]'
}

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.