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
Built Distribution
File details
Details for the file pydantic_schema_sync-0.1.4.tar.gz
.
File metadata
- Download URL: pydantic_schema_sync-0.1.4.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | e2d9984882f0e47617be4e4547d15074a57bf24d36bf0286065c6e4053c4e725 |
|
MD5 | e841fcd28466d024fc26ed3902afed7c |
|
BLAKE2b-256 | d7d1a3a98adbebd00585b0a41e95ab189013ad5ec0ae385293a146fe1bfed263 |
File details
Details for the file pydantic_schema_sync-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: pydantic_schema_sync-0.1.4-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.18.1 CPython/3.10.14 Linux/5.15.0-117-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 112e79cc3d051c0e17b5a15751c56bf04765fd418efa77ad95566987d7294fb8 |
|
MD5 | 2ae38b1db4c79485a830912496f1f431 |
|
BLAKE2b-256 | 2616cf7ce807158890f4639bc47714f152bd9a3f752033064a7fdd04f2bf945a |