{"id":6324,"library":"bravado-core","title":"Bravado Core","description":"bravado-core is a Python library that implements the Swagger 2.0 (OpenAPI Specification v2.0). It provides core functionalities for both client-side and server-side support, including Swagger Schema ingestion and validation, marshalling and unmarshalling of requests and responses, and modeling Swagger definitions as Python classes or dictionaries. The current version is 6.1.1, and it maintains an active, though not rapid, release cadence with new versions typically addressing bugs or minor features rather than frequent major changes.","status":"active","version":"6.1.1","language":"en","source_language":"en","source_url":"https://github.com/Yelp/bravado-core","tags":["swagger","openapi","validation","schema","rest","client","server","api-specification"],"install":[{"cmd":"pip install bravado-core","lang":"bash","label":"Install stable release"}],"dependencies":[{"reason":"Used for JSON schema validation. Specific version constraints (>=2.5.1,<4.0.0) are important for compatibility.","package":"jsonschema","optional":false},{"reason":"Validates the Swagger/OpenAPI specification itself.","package":"swagger-spec-validator","optional":false},{"reason":"Used for loading YAML-based Swagger/OpenAPI specifications.","package":"pyyaml","optional":false},{"reason":"HTTP client library, used for resolving remote references in specs.","package":"requests","optional":false},{"reason":"Handles JSON references ($ref) within the specification.","package":"jsonref","optional":false},{"reason":"Python 2 and 3 compatibility utilities.","package":"six","optional":false}],"imports":[{"note":"The central object for loading and interacting with a Swagger/OpenAPI specification.","symbol":"Spec","correct":"from bravado_core.spec import Spec"},{"note":"Used to define and register custom data formats for validation and marshalling.","symbol":"SwaggerFormat","correct":"from bravado_core.formatter import SwaggerFormat"},{"note":"Exception raised by bravado-core during validation failures.","symbol":"SwaggerValidationError","correct":"from bravado_core.exception import SwaggerValidationError"}],"quickstart":{"code":"import json\nfrom bravado_core.spec import Spec\nfrom bravado_core.validate import validate_object\n\n# Example Swagger 2.0 spec (usually loaded from a file or URL)\nswagger_dict = {\n    \"swagger\": \"2.0\",\n    \"info\": {\"title\": \"Test API\", \"version\": \"1.0.0\"},\n    \"paths\": {},\n    \"definitions\": {\n        \"Pet\": {\n            \"type\": \"object\",\n            \"required\": [\"name\"],\n            \"properties\": {\n                \"name\": {\"type\": \"string\"},\n                \"age\": {\"type\": \"integer\", \"format\": \"int32\", \"minimum\": 0}\n            }\n        }\n    }\n}\n\n# Load the spec\nspec = Spec.from_dict(swagger_dict)\nprint(\"Swagger spec loaded successfully.\")\n\n# Access a defined model\nPet = spec.definitions['Pet']\nmy_pet = Pet(name='Rex', age=5)\nprint(f\"Created Pet object: Name={my_pet.name}, Age={my_pet.age}\")\n\n# Validate an object against a schema\nvalid_pet_data = {'name': 'Whiskers', 'age': 2}\ntry:\n    validate_object(swagger_spec=spec, json_value=valid_pet_data, swagger_type=spec.definitions['Pet'].swagger_spec)\n    print(f\"Valid pet data: {valid_pet_data} is valid.\")\nexcept Exception as e:\n    print(f\"Validation failed for valid data: {e}\")\n\ninvalid_pet_data = {'name': 'Buddy', 'age': -1}\ntry:\n    validate_object(swagger_spec=spec, json_value=invalid_pet_data, swagger_type=spec.definitions['Pet'].swagger_spec)\n    print(\"This line should not be reached for invalid data.\")\nexcept Exception as e:\n    print(f\"Validation error for invalid pet data: {invalid_pet_data} -> {e}\")","lang":"python","description":"This quickstart demonstrates how to load a Swagger/OpenAPI specification using `Spec.from_dict`, access defined models as Python types, and validate data against those models. It highlights basic model instantiation and the core validation feature of `bravado-core`."},"warnings":[{"fix":"Use the `is_equal` methods provided by `bravado-core` for comparing `Spec` objects if equality checking is required.","message":"In version 5.17.0, the equality (==) feature on `Spec` objects was removed. Direct comparison using `==` will no longer work as expected and might lead to errors or unexpected behavior.","severity":"breaking","affected_versions":">=5.17.0"},{"fix":"Review the changelog and migration guides for `bravado-core` 5.0.0. Update calls to `flattened_spec` with the new signature and replace usage of removed model-related public methods with their new equivalents or recommended patterns.","message":"Version 5.0.0 introduced significant breaking changes, including a refactoring of model discovery. The signature of `bravado_core.spec_flattening.flattened_spec` was updated, and several public methods (e.g., `tag_models`, `bless_models`, `collect_models` from `bravado_core.model`, and `post_process_spec` from `bravado_core.spec`) were removed or changed their interface.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Ensure that your `jsonschema` dependency is pinned to a version compatible with your `bravado-core` installation, typically `jsonschema>=2.5.1,<4.0.0` as specified by `bravado-core`'s `install_requires`. If using a system that requires `jsonschema>=4.0.0`, consider upgrading `bravado-core` to a version that officially supports it, if available, or finding a workaround.","message":"Older versions of `bravado-core` (specifically those constrained by `jsonschema<4.0.0`) are not compatible with `jsonschema>=4.0.0`. Using a newer `jsonschema` might cause `bravado-core` to break, especially in offline environments where dependency resolution might be less strict.","severity":"gotcha","affected_versions":"<6.0.0"},{"fix":"Always provide a correct `origin_url` when using `Spec.from_dict()` for local files. For example, use `Path.cwd().as_uri()` or a suitable file URI for the `origin_url` parameter.","message":"When loading a spec using `Spec.from_dict()`, the `spec.definitions` dictionary (which contains the Python models) might appear empty if the `origin_url` parameter is not provided or is incorrect, especially when loading local files. `bravado-core` relies on `origin_url` to correctly resolve internal references and build models.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Define custom formats using `bravado_core.formatter.SwaggerFormat` and pass them in the `config` dictionary when creating the `Spec` object (e.g., `config={'formats': [my_custom_format]}`).","message":"If your Swagger/OpenAPI spec defines custom formats (e.g., 'uuid', 'email', 'guid') and these are not registered with `bravado-core` via `SwaggerFormat`, you will see warnings like 'X format is not registered with bravado-core!' This can lead to validation issues or incorrect data handling for these formats.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to Python 3.7 or newer. The current recommended Python version is >=3.7.","message":"Support for Python 3.5 was dropped in `bravado-core` version 5.17.0. While earlier versions might still work, they are no longer officially supported.","severity":"deprecated","affected_versions":"<5.17.0"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}