OpenAPI v3 parser that transforms specification documents into structured Python objects for programmatic access and manipulation
—
The specification structure represents the root OpenAPI document and its core metadata components. This includes the main Specification container, API information, server configurations, and documentation references that define the overall API context.
The top-level container that holds the complete parsed OpenAPI specification with all its components.
@dataclass
class Specification:
version: str
info: Info
servers: list[Server] = field(default_factory=list)
tags: list[Tag] = field(default_factory=list)
security_schemas: dict[str, Security] = field(default_factory=dict)
security: list[dict[str, Any]] = field(default_factory=list)
schemas: dict[str, Schema] = field(default_factory=dict)
external_docs: Optional[ExternalDoc] = None
paths: list[Path] = field(default_factory=list)
extensions: Optional[dict] = field(default_factory=dict)Properties:
version: OpenAPI specification version (e.g., "3.0.0")info: API metadata and informationservers: List of server configurations where the API is hostedpaths: API endpoints and their operationssecurity: Global security requirementstags: Metadata for grouping operationsexternal_docs: Reference to external documentationsecurity_schemas: Reusable security scheme definitionsschemas: Reusable schema componentsextensions: Custom extensions (x-* properties)Metadata about the API including title, version, description, and contact information.
@dataclass
class Info:
title: str
version: str
description: Optional[str] = None
terms_of_service: Optional[str] = None
contact: Optional[Contact] = None
license: Optional[License] = None
extensions: Optional[dict] = field(default_factory=dict)Properties:
title: API title/name (required)version: API version string (required)description: Detailed API description with CommonMark syntax supportterms_of_service: URL to terms of servicecontact: Contact information for the APIlicense: License information for the APIextensions: Custom info extensionsContact details for the API maintainers or support team.
@dataclass
class Contact:
name: Optional[str] = None
url: Optional[str] = None
email: Optional[str] = NoneProperties:
name: Contact name/organizationurl: Contact website or support URLemail: Contact email addressLicensing information for the API.
@dataclass
class License:
name: str
url: Optional[str] = None
extensions: Optional[dict] = field(default_factory=dict)Properties:
name: License name (required)url: URL to the license textextensions: Custom license extensionsServer information specifying where the API is accessible.
@dataclass
class Server:
url: str
description: Optional[str] = None
variables: Optional[dict] = field(default_factory=dict)
extensions: Optional[dict] = field(default_factory=dict)Properties:
url: Server URL template (required). May contain variables in {brackets}description: Human-readable server descriptionvariables: Variable definitions for URL template substitutionextensions: Custom server extensionsReference to external documentation resources.
@dataclass
class ExternalDoc:
url: str
description: Optional[str] = None
extensions: Optional[dict] = field(default_factory=dict)Properties:
url: URL to external documentation (required)description: Description of the external documentationextensions: Custom external docs extensionsMetadata for grouping and organizing API operations.
@dataclass
class Tag:
name: str
description: Optional[str] = None
external_docs: Optional[ExternalDoc] = NoneProperties:
name: Tag name (required)description: Tag descriptionexternal_docs: Additional external documentation for this tagAccess API metadata:
from openapi_parser import parse
spec = parse('api-spec.yml')
# Basic API information
print(f"API: {spec.info.title} v{spec.info.version}")
print(f"Description: {spec.info.description}")
# Contact information
if spec.info.contact:
contact = spec.info.contact
print(f"Contact: {contact.name} ({contact.email})")
# License information
if spec.info.license:
print(f"License: {spec.info.license.name}")Access server configurations:
# List all servers
for server in spec.servers:
print(f"Server: {server.url}")
if server.description:
print(f" Description: {server.description}")
# Server variables
for var_name, var_def in (server.variables or {}).items():
print(f" Variable {var_name}: {var_def}")Work with tags:
# List all tags
for tag in spec.tags:
print(f"Tag: {tag.name}")
if tag.description:
print(f" Description: {tag.description}")Install with Tessl CLI
npx tessl i tessl/pypi-openapi3-parser