jsf


Namejsf JSON
Version 0.11.2 PyPI version JSON
download
home_pagehttps://github.com/ghandic/jsf
SummaryCreates fake JSON files from a JSON schema
upload_time2024-03-26 02:04:38
maintainerNone
docs_urlNone
authorghandic
requires_python>=3.8
licenseNone
keywords json schema fake data test data schema json faker hypothesis rapid prototype data contract
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center">
   <strong>jsf</strong><img src="docs/assets/imgs/index.png" width="50" style="position: absolute; padding-left:10px;">
</h1>

<p align="center">
    <a href="https://codecov.io/gh/ghandic/jsf" target="_blank">
        <img src="https://img.shields.io/codecov/c/github/ghandic/jsf?color=%2334D058" alt="Coverage">
    </a>
    <a href="https://ghandic.github.io/jsf/index.html" target="_blank">
        <img src="https://img.shields.io/badge/docs-mkdocs%20material-blue.svg?style=flat" alt="Docs">
    </a>
    <a href="https://pypi.org/project/jsf/" target="_blank">
        <img src="https://img.shields.io/pypi/v/jsf.svg" alt="PyPI Latest Release">
    </a>
    <br />
    <a href="https://github.com/ghandic/jsf/blob/main/LICENSE" target="_blank">
        <img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License">
    </a>
    <a href="https://github.com/psf/black" target="_blank">
        <img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code style: black">
    </a>
</p>

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](https://fastapi.tiangolo.com/) 🚀

## Installation

<div class="termy">

```console
$ pip install jsf

---> 100%
```

</div>

## Usage

### Basic 😊

```python
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 ...

```python
{
    'name': 'Jesse Phillips', 
    'email': 'xroberson@hotmail.com'
}
```

### From JSON file 📁

```python
from jsf import JSF

faker = JSF.from_json("demo-schema.json")
fake_json = faker.generate()
```

<details markdown="1">
<summary>Or run straight from the <code>commandline</code>...</summary>

#### 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
```

</details>

### FastAPI Integration 🚀

Create a file main.py with:

```python
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:

<div class="termy">

```console
$ 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](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)

</div>

### 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)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ghandic/jsf",
    "name": "jsf",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "JSON Schema, Fake data, Test data, Schema, JSON, Faker, Hypothesis, Rapid Prototype, Data contract",
    "author": "ghandic",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/8d/34/cf272dfe4277ce03b275bb9f5e99001b31db01b21c290fd262333c96e34a/jsf-0.11.2.tar.gz",
    "platform": null,
    "description": "<h1 align=\"center\">\n   <strong>jsf</strong><img src=\"docs/assets/imgs/index.png\" width=\"50\" style=\"position: absolute; padding-left:10px;\">\n</h1>\n\n<p align=\"center\">\n    <a href=\"https://codecov.io/gh/ghandic/jsf\" target=\"_blank\">\n        <img src=\"https://img.shields.io/codecov/c/github/ghandic/jsf?color=%2334D058\" alt=\"Coverage\">\n    </a>\n    <a href=\"https://ghandic.github.io/jsf/index.html\" target=\"_blank\">\n        <img src=\"https://img.shields.io/badge/docs-mkdocs%20material-blue.svg?style=flat\" alt=\"Docs\">\n    </a>\n    <a href=\"https://pypi.org/project/jsf/\" target=\"_blank\">\n        <img src=\"https://img.shields.io/pypi/v/jsf.svg\" alt=\"PyPI Latest Release\">\n    </a>\n    <br />\n    <a href=\"https://github.com/ghandic/jsf/blob/main/LICENSE\" target=\"_blank\">\n        <img src=\"https://img.shields.io/badge/License-MIT-yellow.svg\" alt=\"License\">\n    </a>\n    <a href=\"https://github.com/psf/black\" target=\"_blank\">\n        <img src=\"https://img.shields.io/badge/code%20style-black-000000.svg\" alt=\"Code style: black\">\n    </a>\n</p>\n\nUse **jsf** along with fake data generators to provide consistent and meaningful fake data for your system.\n\n## Main Features\n\n- Provides out of the box data generation from any JSON schema \ud83d\udce6\n- Extendable custom data providers using any lambda functions \ud83d\udd17\n- Multi level state for dependant data (eg multiple objects sharing value, such as children with same surname) \ud83e\udd13\n- Inbuilt validation of fake JSON produced \u2705\n- In memory conversion from JSON Schema to Pydantic Models with generated examples \ud83e\udd2f\n- Seamless integration with [FastAPI](https://fastapi.tiangolo.com/) \ud83d\ude80\n\n## Installation\n\n<div class=\"termy\">\n\n```console\n$ pip install jsf\n\n---> 100%\n```\n\n</div>\n\n## Usage\n\n### Basic \ud83d\ude0a\n\n```python\nfrom jsf import JSF\n\nfaker = JSF(\n    {\n        \"type\": \"object\",\n        \"properties\": {\n            \"name\": {\"type\": \"string\", \"$provider\": \"faker.name\"},\n            \"email\": {\"type\": \"string\", \"$provider\": \"faker.email\"},\n        },\n        \"required\": [\"name\", \"email\"],\n    }\n)\n\nfake_json = faker.generate()\n```\n\nResults in ...\n\n```python\n{\n    'name': 'Jesse Phillips', \n    'email': 'xroberson@hotmail.com'\n}\n```\n\n### From JSON file \ud83d\udcc1\n\n```python\nfrom jsf import JSF\n\nfaker = JSF.from_json(\"demo-schema.json\")\nfake_json = faker.generate()\n```\n\n<details markdown=\"1\">\n<summary>Or run straight from the <code>commandline</code>...</summary>\n\n#### Native install\n\n```bash\npip install jsf[cli]\njsf --schema jsf/tests/data/custom.json --instance wow.json\n```\n\n#### Docker\n\n```bash\ndocker run -v $PWD:/data challisa/jsf jsf --schema /data/custom.json --instance /data/example.json\n```\n\n</details>\n\n### FastAPI Integration \ud83d\ude80\n\nCreate a file main.py with:\n\n```python\nfrom jsf import JSF\nfrom fastapi import FastAPI\n\napp = FastAPI(docs_url=\"/\")\ngenerator = JSF.from_json(\"custom.json\")\n\n\n@app.get(\"/generate\", response_model=generator.pydantic())\ndef read_root():\n    return generator.generate()\n\n```\n\nRun the server with:\n\n<div class=\"termy\">\n\n```console\n$ uvicorn main:app --reload\n\nINFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)\nINFO:     Started reloader process [28720]\nINFO:     Started server process [28722]\nINFO:     Waiting for application startup.\nINFO:     Application startup complete.\n```\n\nNavigate 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:\n\n- Schema with descriptions and examples\n- Example response\n- Data generation by clicking \"try it out\"\n\n![Example Swagger UI - Page 1](docs/assets/imgs/ui-1.png)\n![Example Swagger UI - Page 2](docs/assets/imgs/ui-2.png)\n![Example Swagger UI - Page 3](docs/assets/imgs/ui-3.png)\n![Example Swagger UI - Page 4](docs/assets/imgs/ui-4.png)\n\n</div>\n\n### Partially supported features\n\n- 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)  \n\n## Credits\n\n- 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.\n\n## License\n\n- [MIT License](/LICENSE)\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Creates fake JSON files from a JSON schema",
    "version": "0.11.2",
    "project_urls": {
        "Homepage": "https://github.com/ghandic/jsf"
    },
    "split_keywords": [
        "json schema",
        " fake data",
        " test data",
        " schema",
        " json",
        " faker",
        " hypothesis",
        " rapid prototype",
        " data contract"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0aae7435288ab8b3059823afa48508ddf658c27d96deb8a978498103ccd71ca8",
                "md5": "1f7f01c3917c1c4490f017cf0b428f9c",
                "sha256": "b4472c8c2d776eb3e0bb08368caa6ae0ead7ea78b20653facc07b6d93768612c"
            },
            "downloads": -1,
            "filename": "jsf-0.11.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1f7f01c3917c1c4490f017cf0b428f9c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 49322,
            "upload_time": "2024-03-26T02:04:37",
            "upload_time_iso_8601": "2024-03-26T02:04:37.013101Z",
            "url": "https://files.pythonhosted.org/packages/0a/ae/7435288ab8b3059823afa48508ddf658c27d96deb8a978498103ccd71ca8/jsf-0.11.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8d34cf272dfe4277ce03b275bb9f5e99001b31db01b21c290fd262333c96e34a",
                "md5": "e59faa8668bc364be0d83fe7db63e05e",
                "sha256": "07055b363281d38ce871a9256a00587d8472802c5108721a7fe5884465104b5d"
            },
            "downloads": -1,
            "filename": "jsf-0.11.2.tar.gz",
            "has_sig": false,
            "md5_digest": "e59faa8668bc364be0d83fe7db63e05e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 29837,
            "upload_time": "2024-03-26T02:04:38",
            "upload_time_iso_8601": "2024-03-26T02:04:38.893523Z",
            "url": "https://files.pythonhosted.org/packages/8d/34/cf272dfe4277ce03b275bb9f5e99001b31db01b21c290fd262333c96e34a/jsf-0.11.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-26 02:04:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ghandic",
    "github_project": "jsf",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "jsf"
}
        
Elapsed time: 0.22221s