{"id":1600,"library":"openapi-core","title":"OpenAPI Core","description":"openapi-core provides client-side and server-side support for validating requests and responses against the OpenAPI Specification v3.x and v3.2. It integrates with various web frameworks like Flask, Starlette, Falcon, Django, and aiohttp. The current version is 0.23.1, with a frequent release cadence to support new Python versions and framework updates.","status":"active","version":"0.23.1","language":"en","source_language":"en","source_url":"https://github.com/python-openapi/openapi-core","tags":["openapi","validation","api","web","server","rest"],"install":[{"cmd":"pip install openapi-core","lang":"bash","label":"Base installation"},{"cmd":"pip install openapi-core[flask,starlette,falcon,django,aiohttp]","lang":"bash","label":"With web framework integrations"}],"dependencies":[{"reason":"Used for schema validation, core dependency.","package":"jsonschema"},{"reason":"Used for validating the OpenAPI specification itself.","package":"openapi-spec-validator","optional":false},{"reason":"Optional integration for Flask applications.","package":"flask","optional":true},{"reason":"Optional integration for Starlette/FastAPI applications.","package":"starlette","optional":true},{"reason":"Optional integration for Falcon applications.","package":"falcon","optional":true},{"reason":"Optional integration for Django applications.","package":"django","optional":true},{"reason":"Optional integration for aiohttp applications.","package":"aiohttp","optional":true}],"imports":[{"note":"Main class to load and parse an OpenAPI specification.","symbol":"OpenAPI","correct":"from openapi_core import OpenAPI"},{"note":"Used for server-side request validation.","symbol":"RequestValidator","correct":"from openapi_core.validation.request.validators import RequestValidator"},{"note":"Used for server-side response validation.","symbol":"ResponseValidator","correct":"from openapi_core.validation.response.validators import ResponseValidator"},{"note":"Example of a wrapper for request objects. Specific framework wrappers are available in `openapi_core.contrib.*`","symbol":"OpenAPIRequest","correct":"from openapi_core.wrappers.mock import MockRequest as OpenAPIRequest"},{"note":"Example of a wrapper for response objects. Specific framework wrappers are available in `openapi_core.contrib.*`","symbol":"OpenAPIResponse","correct":"from openapi_core.wrappers.mock import MockResponse as OpenAPIResponse"}],"quickstart":{"code":"import io\nfrom openapi_core import OpenAPI\nfrom openapi_core.validation.request.validators import RequestValidator\nfrom openapi_core.validation.response.validators import ResponseValidator\nfrom openapi_core.wrappers.mock import MockRequest, MockResponse\n\n# Define a simple OpenAPI spec\noas_spec = {\n    \"openapi\": \"3.0.0\",\n    \"info\": {\"title\": \"Test API\", \"version\": \"1.0.0\"},\n    \"paths\": {\n        \"/hello\": {\n            \"get\": {\n                \"parameters\": [\n                    {\n                        \"name\": \"name\",\n                        \"in\": \"query\",\n                        \"required\": True,\n                        \"schema\": {\"type\": \"string\"}\n                    }\n                ],\n                \"responses\": {\n                    \"200\": {\n                        \"description\": \"A greeting\",\n                        \"content\": {\n                            \"application/json\": {\n                                \"schema\": {\"type\": \"object\", \"properties\": {\"message\": {\"type\": \"string\"}}}\n                            }\n                        }\n                    }\n                }\n            }\n        }\n    }\n}\n\n# Load the OpenAPI specification\nopenapi = OpenAPI.from_dict(oas_spec)\n\n# --- Request Validation ---\n\n# Create a mock request for validation\nrequest = MockRequest(\n    host_url=\"http://localhost\",\n    path=\"/hello\",\n    method=\"get\",\n    query_string=\"name=World\"\n)\n\nvalidator = RequestValidator(openapi)\nresult = validator.validate(request)\n\nif result.errors:\n    print(f\"Request validation errors: {result.errors}\")\nelse:\n    print(\"Request validated successfully.\")\n    # Access validated parameters\n    print(f\"Validated query parameters: {result.parameters.query}\")\n\n# --- Response Validation ---\n\n# Create a mock response for validation\nresponse = MockResponse(\n    data=io.BytesIO(b'{\"message\": \"Hello, World!\"}'),\n    status_code=200,\n    mimetype=\"application/json\"\n)\n\nvalidator = ResponseValidator(openapi)\nresult = validator.validate(request, response)\n\nif result.errors:\n    print(f\"Response validation errors: {result.errors}\")\nelse:\n    print(\"Response validated successfully.\")\n","lang":"python","description":"This quickstart demonstrates loading an OpenAPI specification, creating mock requests and responses, and then using `RequestValidator` and `ResponseValidator` to validate them against the loaded spec. It covers both request parameters and response body validation. In real-world scenarios, you would use framework-specific request/response wrappers (e.g., `FlaskRequest`, `StarletteRequest`)."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or newer.","message":"Support for Python 3.9 was dropped in version 0.23.0b1. Support for Python 3.8 was dropped in version 0.20.0.","severity":"breaking","affected_versions":"0.20.0, 0.23.0b1 and later"},{"fix":"Review your imports related to `openapi_core.spec` and adjust them to the new V32 structure or use the main `OpenAPI` class for abstraction where possible.","message":"With the introduction of OpenAPI 3.2 support, older 'V3 aliases' for specification components have been moved to 'V32' paths. For example, if you were directly importing from `openapi_core.spec.v3_0` it might need adjustment if those aliases were changed or removed.","severity":"breaking","affected_versions":"0.23.0 and later"},{"fix":"Use the `base_uri` parameter directly in `OpenAPI.from_dict()` or `OpenAPI.from_file()` instead.","message":"The `spec_base_uri` configuration parameter for `OpenAPI` initialization is deprecated.","severity":"deprecated","affected_versions":"0.19.3 and later"},{"fix":"If you relied on implicit defaults, you might need to explicitly configure these factories or update your code to handle `None` where a default factory was previously expected.","message":"The defaults for `style_deserializers_factory` and `media_tyles_deserialization_factory` in configuration and protocols were changed to `None`.","severity":"breaking","affected_versions":"0.22.0 and later"},{"fix":"If you encounter unexpected validation errors for properties not explicitly defined in your OpenAPI schema, consider whether you have enabled the strict mode or if your schema implicitly disallows additional properties. Adjust your schema or disable strict mode if necessary.","message":"Version 0.23.0 introduced an opt-in strict mode for omitted `additionalProperties`. By default, `additionalProperties` are allowed if not explicitly forbidden in the schema, but this mode can make validation stricter.","severity":"gotcha","affected_versions":"0.23.0 and later"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}