{"library":"openapi3","title":"OpenAPI 3 Specification Client and Validator","description":"openapi3 is a Python library designed to act as both a client and validator for OpenAPI 3 Specifications. It allows developers to load OpenAPI specification files (YAML or JSON), parse them into Python objects, validate the specification's structure, and interact with the described API by calling defined operations. The library aims to provide an interactive client experience, handling authentication and parameter passing. The current version is 1.8.2, and releases are made as features are developed and bugs are fixed, though a strict cadence isn't published. The project's roadmap indicates ongoing development for richer model and parameter handling.","language":"python","status":"active","last_verified":"Sun May 17","install":{"commands":["pip install openapi3"],"cli":null},"imports":["from openapi3 import OpenAPI"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport yaml\nfrom openapi3 import OpenAPI\n\n# Example OpenAPI 3.0 Specification (simplified for demonstration)\n# In a real scenario, load this from a file or URL.\nspec_content = \"\"\"\nopenapi: 3.0.0\ninfo:\n  title: Example API\n  version: 1.0.0\npaths:\n  /regions:\n    get:\n      operationId: getRegions\n      summary: Get available regions\n      responses:\n        '200':\n          description: A list of regions\n          content:\n            application/json:\n              schema:\n                type: array\n                items:\n                  type: string\n  /secure-data:\n    get:\n      operationId: getSecureData\n      summary: Get secure data\n      security:\n        - personalAccessToken: []\n      responses:\n        '200':\n          description: Secure data\n          content:\n            application/json:\n              schema:\n                type: object\n                properties:\n                  data:\n                    type: string\ncomponents:\n  securitySchemes:\n    personalAccessToken:\n      type: http\n      scheme: bearer\n      bearerFormat: JWT\n\"\"\"\n\n# Load the spec (e.g., from a string, or a file)\nspec = yaml.safe_load(spec_content)\n\n# Parse the spec into a Python object\napi = OpenAPI(spec)\n\n# Call an operation that does not require authentication\ntry:\n    regions = api.call_getRegions()\n    print(f\"Available regions: {regions}\")\nexcept Exception as e:\n    print(f\"Error calling getRegions: {e}\")\n\n# Authenticate for operations that require it\nmy_token = os.environ.get('API_BEARER_TOKEN', 'YOUR_SUPER_SECRET_TOKEN')\nif my_token == 'YOUR_SUPER_SECRET_TOKEN':\n    print(\"Warning: Please set the API_BEARER_TOKEN environment variable for authentication.\")\n\n# Note: The `authenticate` method expects the security scheme name and the credentials.\n# For 'http' 'bearer', it typically expects the token string directly.\n# The example in docs uses `api.authenticate('personalAccessToken', my_token)` for a bearer token.\n# However, the exact usage might depend on how the spec defines the security scheme\n# and how the `openapi3` library interprets it.\n# As per the library's docs, `api.authenticate('personalAccessToken', my_token)` is correct for bearer.\n\nif my_token:\n    try:\n        api.authenticate('personalAccessToken', my_token)\n        secure_data = api.call_getSecureData()\n        print(f\"Secure data: {secure_data}\")\n    except Exception as e:\n        print(f\"Error calling getSecureData: {e}\")\nelse:\n    print(\"Skipping authenticated call as API_BEARER_TOKEN is not set.\")\n","lang":"python","description":"This quickstart demonstrates how to load an OpenAPI 3.0 specification from a string (or file), initialize the `OpenAPI` client, call an unauthenticated operation, and then authenticate to call a secured operation. It uses `PyYAML` to parse the YAML spec and `os.environ.get` for securely handling API tokens.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-17","installed_version":"1.8.2","pypi_latest":"1.8.2","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.3,"avg_import_s":0.6,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"openapi3","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.56,"mem_mb":9.9,"disk_size":"23.5M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"openapi3","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.3,"import_time_s":0.43,"mem_mb":9.9,"disk_size":"25M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"openapi3","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.72,"mem_mb":11,"disk_size":"25.8M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"openapi3","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.3,"import_time_s":0.63,"mem_mb":11,"disk_size":"27M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"openapi3","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.68,"mem_mb":11.5,"disk_size":"17.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"openapi3","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2,"import_time_s":0.68,"mem_mb":11.5,"disk_size":"19M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"openapi3","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.72,"mem_mb":11.8,"disk_size":"17.4M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"openapi3","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.1,"import_time_s":0.65,"mem_mb":11.8,"disk_size":"19M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"openapi3","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.51,"mem_mb":9.6,"disk_size":"22.7M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"openapi3","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.6,"import_time_s":0.45,"mem_mb":9.6,"disk_size":"24M"}]}}