Skip to main content

Turn OpenAPI schemas into Pydantic models

Project description

📜 Cicerone

Turn OpenAPI schemas into Pydantic models

Package version codecov PyPI - License

Cicerone parses OpenAPI schemas into Pydantic models for introspection and traversal.

Cicerone is the fastest, most minimal, fully typed, pythonic library for dealing with OpenAPI schemas.

Features

  • Full support: Tested against hundreds of real schemas to ensure 100% compliance.
  • Pydantic-based models: Type-safe object models.
  • Multiple input formats: Load from files, URLs, or in-memory data in various formats.
  • OpenAPI 3.x support: Works with OpenAPI 3.0 and 3.1 specifications
  • Minimal dependencies: Only relies on Pydantic and pyyaml. The rest is core Python.
  • Simple API: Intuitive methods for common operations.
  • Modern Python: Fully typed and 100% test coverage codebase.

Installation

pip

pip install cicerone

uv

uv add cicerone

Quick Start

Parsing Specifications

from cicerone import parse as cicerone_parse

# From a file
file_spec = cicerone_parse.parse_spec_from_file("openapi.yaml")

# From a URL
url_spec = cicerone_parse.parse_spec_from_url("https://api.example.com/openapi.json")

# From a dictionary
dict_spec = cicerone_parse.parse_spec_from_dict({"openapi": "3.0.0", ...})

# From JSON string
json_spec = cicerone_parse.parse_spec_from_json('{"openapi": "3.0.0", ...}')

# From YAML string
yaml_spec = cicerone_parse.parse_spec_from_yaml('openapi: "3.0.0"\n...')

Exploring the schema

from cicerone import parse as cicerone_parse

spec = cicerone_parse.parse_spec_from_file('tests/fixtures/petstore_openapi3.yaml')

print("OpenAPISpec:", spec)
>>> OpenAPISpec: <OpenAPISpec: 'Test API' v3.0.0, 2 paths, 2 schemas>

print("Paths:", spec.paths)
>>> Paths: <Paths: 2 paths, 3 operations [/users, /users/{userId}]>

print("PathItem:", spec.paths["/users"])
>>> PathItem: <PathItem: /users [GET, POST]>

print("Operation:", spec.operation_by_operation_id("listUsers"))
>>> Operation: <Operation: GET /users, id=listUsers, 'List all users', tags=['users']>

print("Components:", spec.components)
>>> Components: <Components: 2 schemas [User, Error]>

print("Schema:", spec.components.get_schema("User"))
>>> Schema: <Schema: type=object, 5 properties, required=['id', 'username', 'email']>

user = spec.components.get_schema("User")
print(f"User properties: {list(user.properties.keys())}")
>>> User properties: ['id', 'username', 'email', 'age', 'roles']

Resolving References

Resolve $ref references to their typed objects:

from cicerone import parse as cicerone_parse

spec = cicerone_parse.parse_spec_from_file('tests/fixtures/petstore_openapi3.yaml')

# Resolve a reference to get a typed Schema object
# follow_nested=True will recursively resolve all nested $refs
user_schema = spec.resolve_reference('#/components/schemas/User', follow_nested=True)
print(f"User schema type: {user_schema.type}")
>>> User schema type: object
print(f"Required fields: {user_schema.required}")
>>> Required fields: ['id', 'username', 'email']

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

cicerone-0.2.0.tar.gz (249.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cicerone-0.2.0-py3-none-any.whl (33.5 kB view details)

Uploaded Python 3

File details

Details for the file cicerone-0.2.0.tar.gz.

File metadata

  • Download URL: cicerone-0.2.0.tar.gz
  • Upload date:
  • Size: 249.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.6

File hashes

Hashes for cicerone-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e752e466f3254202f1e2df63c5cb92b7068797f7bc51d7bf693b73b4499687c5
MD5 1e4514454e854d5392fac2229ea0fd61
BLAKE2b-256 a41da564a73936aacbafbbbe91894899c8c38b2f36b6d7cacc0ae95678ad329c

See more details on using hashes here.

File details

Details for the file cicerone-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: cicerone-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 33.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.6

File hashes

Hashes for cicerone-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 77933397834a0052ba17c801dfe77f1cea2f98686f677085ac6a077b981888c1
MD5 fca5b22ccbe76ac106a6c6b5b7fb8ce2
BLAKE2b-256 eab644948cb327929739fc02900364f7cb19001ae5cd3321d9f1fc56916b2bea

See more details on using hashes here.

Supported by

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