Skip to main content

python-cydantic

conao3's pydantic CLI wrapper.

Install

Install from PyPI

release soon.

Install from Source

poetry install

Usage

generate

Prepare pydantic model named Model.

import pydantic


class Model(pydantic.BaseModel):
    name: str = 'John Doe'
    age: int = 20

Generate Model's schema.

$ cydantic generate -s sample/schema01.py
{
  "properties": {
    "name": {
      "default": "John Doe",
      "title": "Name",
      "type": "string"
    },
    "age": {
      "default": 20,
      "title": "Age",
      "type": "integer"
    }
  },
  "title": "Model",
  "type": "object"
}

Output using yaml format.

$ cydantic generate -s sample/schema01.py --format yaml
properties:
  age:
    default: 20
    title: Age
    type: integer
  name:
    default: John Doe
    title: Name
    type: string
title: Model
type: object

validate

$ cydantic validate -s sample/schema01.py -f yaml -i sample/inpt01.json
age: 20
name: conao3

$ cydantic validate -s sample/schema01.py -f yaml -i sample/inpt02.json
age: 18
name: conao3

$ cydantic validate -s sample/schema01.py -f yaml -i sample/inpt03.json
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/conao/dev/repos/python-cydantic/src/cydantic/main.py", line 86, in main
    args.handler(args)
  File "/Users/conao/dev/repos/python-cydantic/src/cydantic/main.py", line 48, in command_validate
    obj = model.model_validate(inpt)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/conao/dev/repos/python-cydantic/.venv/lib/python3.12/site-packages/pydantic/main.py", line 503, in model_validate
    return cls.__pydantic_validator__.validate_python(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for Model
age
  Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='Unknown', input_type=str]
    For further information visit https://errors.pydantic.dev/2.5/v/int_parsing

Release files for cydantic 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cydantic 0.1.0
File Size Uploaded
cydantic-0.1.0.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cydantic 0.1.0
File Interpreter ABI Platform
cydantic-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.7 kB

Release files / cydantic-0.1.0.tar.gz

Download URL cydantic-0.1.0.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
abbcefa3649ebbe8289728eb09837ff65379e84003f1211bc4bfec2aa8a616ce
BLAKE2b-256 checksum
How to use checksums
c741bf89441f9ccd5873924d159f3eb151549d8a806f8101ed76d22e4d5c9f8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.2 Linux/5.10.189-1-MANJARO

Release files / cydantic-0.1.0-py3-none-any.whl

Download URL cydantic-0.1.0-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
803050e7a7da07d1126f5fbe98fe758de4354b3cd1544d79c3a8e238dfabde6c
BLAKE2b-256 checksum
How to use checksums
2e65b7b0041d033b412c7b6bbad5a0bc40bafe0a90bc611e9bc373b27992296b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.2 Linux/5.10.189-1-MANJARO

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page