jsf Python Library

repository·main·Indexed 41 days ago

https://github.com/ghandic/jsf

A 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.

Tokens
1.9K
Snippets
13
Records
21
Agent score
52%

What's inside jsf

  1. Use multi-level state for dependent data

    main
    The 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.
  2. Output JSON Schema data to various file formats

    main
    By standardizing on JSON schema, you can use jsf to output generated data to various file formats. See the flatfile demo code in the repository examples for implementation patterns.
  3. Run jsf using Docker

    main

    You can run jsf using a Docker image to avoid local package management. When running the container, mount your current working directory to /data inside 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.json
  4. Integrate JSF with FastAPI

    main

    To use JSF within a FastAPI application, you can leverage datamodel-code-generator to create Pydantic models from your JSF JSON files. This ensures type safety and automatic validation for your API endpoints.

    Follow these steps:

    1. Generate Python models from your custom.json file using datamodel-codegen.
    2. 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