Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ghandic/jsf
Creates fake JSON files from a JSON schema
https://github.com/ghandic/jsf
commandline faker fastapi jsf json-schema property-based-testing python
Last synced: 4 days ago
JSON representation
Creates fake JSON files from a JSON schema
- Host: GitHub
- URL: https://github.com/ghandic/jsf
- Owner: ghandic
- License: other
- Created: 2021-04-08T15:49:27.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-15T04:11:35.000Z (about 1 month ago)
- Last Synced: 2024-12-14T01:03:16.036Z (11 days ago)
- Topics: commandline, faker, fastapi, jsf, json-schema, property-based-testing, python
- Language: Python
- Homepage: https://ghandic.github.io/jsf
- Size: 1.55 MB
- Stars: 171
- Watchers: 5
- Forks: 34
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-pydantic - jsf - Creates fake JSON files from a JSON schema. (Utilities)
- awesome-pydantic - jsf - Creates fake JSON files from a JSON schema. (Utilities)
README
jsfUse **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](https://fastapi.tiangolo.com/) 🚀## Installation
```console
$ pip install jsf---> 100%
```## Usage
### Basic 😊
```python
from jsf import JSFfaker = 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 ...
```python
{
'name': 'Jesse Phillips',
'email': '[email protected]'
}
```### From JSON file 📁
```python
from jsf import JSFfaker = JSF.from_json("demo-schema.json")
fake_json = faker.generate()
```Or run straight from the
commandline
...#### Native install
```bash
pip install jsf[cli]
jsf --schema jsf/tests/data/custom.json --instance wow.json
```#### Docker
```bash
docker run -v $PWD:/data challisa/jsf jsf --schema /data/custom.json --instance /data/example.json
```### FastAPI Integration 🚀
Create a file main.py with:
```python
from jsf import JSF
from fastapi import FastAPIapp = 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:
```console
$ uvicorn main:app --reloadINFO: 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](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](docs/assets/imgs/ui-1.png)
![Example Swagger UI - Page 2](docs/assets/imgs/ui-2.png)
![Example Swagger UI - Page 3](docs/assets/imgs/ui-3.png)
![Example Swagger UI - Page 4](docs/assets/imgs/ui-4.png)### Partially supported features
- string `contentMediaType` - only a subset of these are supported, however they can be expanded within [this file](jsf/schema_types/string_utils/content_type/__init__.py)
## Credits
- This repository is a Python port of [json-schema-faker](https://github.com/json-schema-faker/json-schema-faker) with some minor differences in implementation.
## License
- [MIT License](/LICENSE)