Registry / http-networking / bravado-core

bravado-core

JSON →
library6.4.1pypypi✓ verified 85d ago

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.

pip install bravado-core
INSTALL
IMPORT
SIG · BRAVADO-CORE
B
bravado-core
http-networkingpythonv6.4.1
Install
4.7s avg
Import
6001ms
Disk
38MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v6.4.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 6.209s · 38.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 4.7s · import 5.794s · 40MB
38MB installed
● package 38MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Spec
from bravado_core.spec import Spec
The central object for loading and interacting with a Swagger/OpenAPI specification.
SwaggerFormat
from bravado_core.formatter import SwaggerFormat
Used to define and register custom data formats for validation and marshalling.
SwaggerValidationError
from bravado_core.exception import SwaggerValidationError
Exception raised by bravado-core during validation failures.

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`.

import json from bravado_core.spec import Spec from bravado_core.validate import validate_object # Example Swagger 2.0 spec (usually loaded from a file or URL) swagger_dict = { "swagger": "2.0", "info": {"title": "Test API", "version": "1.0.0"}, "paths": {}, "definitions": { "Pet": { "type": "object", "required": ["name"], "properties": { "name": {"type": "string"}, "age": {"type": "integer", "format": "int32", "minimum": 0} } } } } # Load the spec spec = Spec.from_dict(swagger_dict) print("Swagger spec loaded successfully.") # Access a defined model Pet = spec.definitions['Pet'] my_pet = Pet(name='Rex', age=5) print(f"Created Pet object: Name={my_pet.name}, Age={my_pet.age}") # Validate an object against a schema valid_pet_data = {'name': 'Whiskers', 'age': 2} try: validate_object(swagger_spec=spec, json_value=valid_pet_data, swagger_type=spec.definitions['Pet'].swagger_spec) print(f"Valid pet data: {valid_pet_data} is valid.") except Exception as e: print(f"Validation failed for valid data: {e}") invalid_pet_data = {'name': 'Buddy', 'age': -1} try: validate_object(swagger_spec=spec, json_value=invalid_pet_data, swagger_type=spec.definitions['Pet'].swagger_spec) print("This line should not be reached for invalid data.") except Exception as e: print(f"Validation error for invalid pet data: {invalid_pet_data} -> {e}")
Debug
Known issues
breakingIn 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.
fix
Use the `is_equal` methods provided by `bravado-core` for comparing `Spec` objects if equality checking is required.
affects: >=5.17.0
breakingVersion 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.
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.
affects: >=5.0.0
gotchaOlder 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.
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.
affects: <6.0.0
gotchaWhen 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.
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.
affects: All versions
gotchaIf 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.
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]}`).
affects: All versions
deprecatedSupport 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.
fix
Upgrade to Python 3.7 or newer. The current recommended Python version is >=3.7.
affects: <5.17.0
Errors
Common errors & fixes
AttributeError: 'NoneType' object has no attribute 'rstrip'
This error was caused by a regression in `bravado-core` versions (e.g., 4.13.3, 4.13.4, 5.0.0, 5.0.1) when `internally_dereference_refs` was enabled in `SwaggerClient` configuration, leading to an uninitialized `api_url` on the `Spec` object.
fix
Upgrade `bravado-core` to version 5.0.2 or newer, which contains the fix for this regression. Alternatively, if upgrading is not an immediate option, disable the `internally_dereference_refs` configuration option.
AttributeError: type object 'SomeBravadoResourceType' has no attribute 'marshal'
This `AttributeError` typically occurred in `bravado-core` versions around 4.7.x due to a regression where generated Python model types lost their `marshal` (and `unmarshal`) methods.
fix
Upgrade `bravado-core` to a version where this regression was fixed (e.g., 4.7.2 or later). The `marshal` and `unmarshal` methods should be called on instances of the model, not the model class itself, but this specific error pointed to a deeper issue with the model generation in affected versions.
jsonschema.exceptions.ValidationError: 'I should be integer :(' is not of type 'integer'
This error occurs when data being validated (either a request or a response) does not conform to the types or constraints defined in the OpenAPI (Swagger 2.0) specification.
fix
Ensure that the data being passed or received strictly adheres to the schema defined in your Swagger/OpenAPI specification. For the example given, provide an integer value instead of a string where an integer is expected.
Warning: JSON format is not registered with bravado-core! category=Warning,
This warning indicates that your Swagger/OpenAPI specification uses a custom format (e.g., 'JSON', 'guid') that `bravado-core` does not have a predefined handler for, and therefore cannot validate or marshal against.
fix
Register a custom formatter for the specified format using `bravado_core.formatter.register_format`. For example, to register a simple pass-through for 'JSON' format, you would define a `SwaggerFormat` and pass it in the `formats` config to `Spec.from_dict` or `SwaggerClient.from_url`.
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
This `TypeError` typically arises during parameter unmarshalling when `bravado-core` attempts to cast a request parameter that is received as a list (e.g., from multiple query parameters with the same name like `param=1&param=2`) to a single non-list type (like `integer`), without the `collectionFormat` being appropriately defined in the Swagger spec.
fix
If the parameter is expected to be an array, define its `type` as 'array' and specify the `collectionFormat` (e.g., 'multi' for `param=1&param=2`) in your Swagger specification. If it should always be a single value, ensure that clients send only a single value for that parameter.
Upgrade
Version history
6.4.1latest on PyPI · released May 12, 2026
Audit
Dependencies
jsonschemarequiredUsed for JSON schema validation. Specific version constraints (>=2.5.1,<4.0.0) are important for compatibility.
swagger-spec-validatorrequiredValidates the Swagger/OpenAPI specification itself.
pyyamlrequiredUsed for loading YAML-based Swagger/OpenAPI specifications.
requestsrequiredHTTP client library, used for resolving remote references in specs.
jsonrefrequiredHandles JSON references ($ref) within the specification.
sixrequiredPython 2 and 3 compatibility utilities.
Agent activity
16 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
bravado-core — pip install bravado-core · libregistry