Skip to main content

OpenAPI v3 parser

Project description

OpenAPI Parser

PyPI - Version PyPI - Downloads PyPI - Python Version PyPI - Format PyPI - License

Parse OpenAPI 3 documents into fully typed Python dataclass objects. Navigate your API specification programmatically — servers, paths, operations, parameters, schemas, security schemes, and more.

Version Status
2.0 Deprecated
3.0 Supported
3.1 In development

Installation

pip install openapi3-parser

Quick Start

from openapi_parser import parse

specification = parse("swagger.yml")
print(specification.info.title)  # e.g. "User example service"

Use Cases

Parse from different sources

# From file path
spec = parse("specs/openapi.yml")

# From URL
spec = parse("https://example.com/openapi.json")

# From raw string
spec = parse(spec_string="""
openapi: "3.0.0"
info:
  title: My API
  version: "1.0.0"
paths: {}
""")

Navigate servers, paths, and operations

specification = parse("swagger.yml")

# List all servers
for server in specification.servers:
    print(f"{server.description} - {server.url}")

# List all paths and their HTTP methods
for path in specification.paths:
    methods = ", ".join(op.method.value for op in path.operations)
    print(f"{path.url}: [{methods}]")

# Inspect operation details
for path in specification.paths:
    for op in path.operations:
        print(f"[{op.method.value}] {path.url}: {op.summary}")
        if op.deprecated:
            print("  (deprecated)")
        if op.operation_id:
            print(f"  operationId: {op.operation_id}")

Enum strictness

By default, content types, string formats, and other enum fields are validated against predefined enums. For specs that use custom values, pass strict_enum=False:

# Accepts non-standard content types like "application/vnd.api+json"
spec = parse("swagger.yml", strict_enum=False)

When strict mode is off, unrecognized values are wrapped in a LooseEnum object instead of raising an error.

Error Handling

from openapi_parser.errors import ParserError

try:
    spec = parse("invalid.yml")
except ParserError as e:
    print(f"Parsing failed: {e}")

Data Model

Parsed documents return a Specification object composed of fully typed dataclasses:

Model Description
Specification Root document — version, info, servers, paths, schemas, security
Info API metadata — title, version, description, contact, license
Server Server definition — url, description, variables
Path URL path — operations, parameters
Operation HTTP method — responses, parameters, request body, security
Parameter Path/query/header/cookie param — schema, style, required
Response Status code, description, content, headers
RequestBody Content, description, required
Content Media type, schema, example
Schema Base type — Integer, Number, String, Boolean, Array, Object, Null
Property Object property — name, schema
OneOf/AnyOf Composition schemas with discriminator support
Security Security scheme — apiKey, http, oauth2, openIdConnect
OAuthFlow OAuth flow — authorization, token, scopes
Header Response header — name, schema, description
Tag Tag with optional external docs
ExternalDoc External documentation reference
Discriminator Polymorphism discriminator — property name, mapping

See the specification module for all available fields and types.

Development

# Install with dev dependencies
uv sync --dev

# Lint
uv run ruff check .
uv run mypy .
uv run ty check .

# Test
uv run pytest

# Format
uv run ruff format .

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

openapi3_parser-1.2.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

openapi3_parser-1.2.0-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file openapi3_parser-1.2.0.tar.gz.

File metadata

  • Download URL: openapi3_parser-1.2.0.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for openapi3_parser-1.2.0.tar.gz
Algorithm Hash digest
SHA256 4c4df2e4b0472c16dd5cf0977727a9352b0620d5c200467cc2a28f1bfb9f18d5
MD5 a25a4be7d8222c870ff00dfa20aeecae
BLAKE2b-256 74f1b561377894efdda7560c523fa8eec5e642c60999d4d920b6962a9ebc015a

See more details on using hashes here.

File details

Details for the file openapi3_parser-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: openapi3_parser-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 28.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for openapi3_parser-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9be08dce8b2b62724c96c18c5f8d67f0ab6413b4cb54c3e18af29790a8d3e80
MD5 6a441d647d6c5edfabca49aecd736f8c
BLAKE2b-256 1497b9f4049114dc6918d55f6f7124121d001d8da36912711eaee0faf5fcc428

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