Skip to main content

Synchronise Pydantic model schemas with JSONSchema files

Project description

pydantic-schema-sync

Synchronise Pydantic model schemas with JSONSchema files.

Usage

CLI

usage: model-schema-sync [-h] [--model MODEL] [--schema_path SCHEMA_PATH]
                         [--mjs_kwargs MJS_KWARGS]

Config for syncing Pydantic model schemas to disk.

options:
  -h, --help            show this help message and exit
  --model MODEL         Dotted import path to the Pydantic model
  --schema_path SCHEMA_PATH
                        File path to save the schema at
  --mjs_kwargs MJS_KWARGS
                        Kwargs to pass `.model_json_schema()`

To serialise the schema of the model named SyncCLI (in the package pydantic_schema_sync's cli module) to the file schema.json, passing the by_alias=False param to .model_json_schema():

model-schema-sync \
  --model pydantic_schema_sync.cli.SyncCLI \
  --schema_path schema.json \
  --mjs_kwargs '{"by_alias": false}'

Python

From a model class:

from pydantic_schema_sync import sync_schema

# Using field alias (default)
sync_schema(model=Foo, schema_path="schema.json")

# Unaliased field
sync_schema(model=Foo, schema_path="schema.json", mjs_kwargs={"by_alias": False})

From a path to a model class:

from pydantic_schema_sync import sync_schema_from_path

# This path must be in an installed package
path_to_model_cls = "pydantic_schema_sync.cli.SyncCLI"
sync_schema_from_path(model=path_to_model_cls, schema_path="schema.json")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_schema_sync-0.1.1.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

pydantic_schema_sync-0.1.1-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_schema_sync-0.1.1.tar.gz.

File metadata

  • Download URL: pydantic_schema_sync-0.1.1.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.18.1 CPython/3.10.14 Linux/5.15.0-117-generic

File hashes

Hashes for pydantic_schema_sync-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a6eabb95c4dff4419af1aef000545773dfab2f032281268d8e810d346435e073
MD5 069a613cb49a6b25befd2c0501a7f229
BLAKE2b-256 51f17cabbfc9e5f41ad4e29836677999221d0719dd62d63cd0c0eebc9d0b37a6

See more details on using hashes here.

File details

Details for the file pydantic_schema_sync-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_schema_sync-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 91a08ce60787ee266c7d15c809c76da15414bbc0c2a92243a842b3a87bacb1a6
MD5 d45dc089cb4134435226c737e15aad8f
BLAKE2b-256 a27866dfe18862dc1d909be73e29df30dff2f8a596dee28dd91591509ea56f4c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page