jsf Python Library
repository·main·Indexed 41 days ago
https://github.com/ghandic/jsfA Python port of json-schema-faker designed to generate consistent and meaningful fake data from JSON schemas. It features a CLI, Docker support, and capabilities for converting JSON schemas to Pydantic models. The library supports custom data providers via lambda functions, multi-level state for dependent data, and integration with FastAPI.
What's inside jsf
- To increase the realism of generated data, you can extend the standard generation capabilities using custom data providers implemented via lambda functions.
Generate data from JSON Schema
mainThejsflibrary provides out-of-the-box data generation based on any standard JSON schema. It also includes built-in validation to ensure the generated fake JSON adheres to the provided schema.Use multi-level state for dependent data
mainThe library supports multi-level state, allowing for the generation of dependent data. This is useful when multiple objects need to share specific values, such as ensuring multiple child objects share the same surname as a parent object.Convert JSON Schema to Pydantic Models
mainYou can perform in-memory conversion from a JSON Schema to Pydantic Models. This process includes the generation of examples within the resulting models.Output JSON Schema data to various file formats
mainBy standardizing on JSON schema, you can usejsfto output generated data to various file formats. See theflatfiledemo code in the repository examples for implementation patterns.Run jsf using Docker
mainYou can run
jsfusing a Docker image to avoid local package management. When running the container, mount your current working directory to/datainside the container so the CLI can access your schema and write the output file.docker build . -t challisa/jsf docker run -v $PWD:/data challisa/jsf jsf --schema /data/jsf/tests/data/custom.json --instance /data/wow.jsonIntegrate jsf with FastAPI
mainThe library offers seamless integration with FastAPI. For implementation details, refer to the official FastAPI demo code in the repository examples.Install jsf via pip
mainInstall the core library using pip:
pip install jsfTo use the command line interface (CLI), install with the
[cli]extra:pip install jsf[cli]pip install jsfDependencies for FastAPI integration
mainThe following packages are required to run the FastAPI example:
FastAPIuvicorndatamodel-code-generator
Install dependencies for the Flat File example
mainTo run the flat file example, ensure the following Python packages are installed in your environment:
typerpandasopenpyxlpyarrowjsonlines
Install the jsf CLI
mainTo use
jsffrom the command line, you must install the package with the[cli]extra to include the necessary dependencies.pip install jsf[cli]Integrate JSF with FastAPI
mainTo use JSF within a FastAPI application, you can leverage
datamodel-code-generatorto create Pydantic models from your JSF JSON files. This ensures type safety and automatic validation for your API endpoints.Follow these steps:
- Generate Python models from your
custom.jsonfile usingdatamodel-codegen. - Run the FastAPI application using
uvicorn.
datamodel-codegen --input jsf/tests/data/custom.json --output model.py uvicorn api:app --reload --host 0.0.0.0 --port 8080- Generate Python models from your