{"id":5866,"library":"bravado","title":"Bravado","description":"Bravado is a Python client library for accessing OpenAPI Specification v2.0 (formerly Swagger) services. It aims to replace code generation by providing a dynamically generated client, supporting both synchronous and asynchronous HTTP requests. The library performs strict validations against the OpenAPI schema for both requests and responses. The current version is 12.0.1, requiring Python 3.8 or newer, and it maintains an active development status with irregular but significant updates.","status":"active","version":"12.0.1","language":"en","source_language":"en","source_url":"https://github.com/Yelp/bravado","tags":["API client","OpenAPI","Swagger","RESTful","HTTP client"],"install":[{"cmd":"pip install bravado","lang":"bash","label":"Standard Install"},{"cmd":"pip install bravado[fido]","lang":"bash","label":"Install with Fido (Async) Client"},{"cmd":"pip install bravado-asyncio","lang":"bash","label":"Install with Asyncio Client"}],"dependencies":[{"reason":"Default synchronous HTTP client.","package":"requests","optional":false},{"reason":"Implements Swagger 2.0 Specification features like schema validation and marshaling.","package":"bravado-core","optional":false},{"reason":"Optional asynchronous HTTP client.","package":"fido","optional":true},{"reason":"Alternative asynchronous HTTP client.","package":"bravado-asyncio","optional":true},{"reason":"Used by bravado-core for spec validation.","package":"swagger-spec-validator","optional":false}],"imports":[{"symbol":"SwaggerClient","correct":"from bravado.client import SwaggerClient"},{"symbol":"RequestsClient","correct":"from bravado.requests_client import RequestsClient"},{"symbol":"FidoClient","correct":"from bravado.fido_client import FidoClient"},{"note":"For the bravado-asyncio optional dependency.","symbol":"AsyncioClient","correct":"from bravado_asyncio.http_client import AsyncioClient"}],"quickstart":{"code":"from bravado.client import SwaggerClient\n\n# Using a publicly available Petstore Swagger/OpenAPI spec\nclient = SwaggerClient.from_url('http://petstore.swagger.io/v2/swagger.json')\n\n# Make a synchronous API call and get the result\ntry:\n    # Using .response().result is the recommended way to get the data\n    pet = client.pet.getPetById(petId=42).response().result\n    print(f\"Found pet: {pet.name} (ID: {pet.id})\")\n\n    # Example of a POST call\n    Pet = client.get_model('Pet')\n    Category = client.get_model('Category')\n    new_pet = Pet(id=100, name=\"Buddy\", category=Category(id=1, name=\"Dogs\"), photoUrls=[])\n    add_result = client.pet.addPet(body=new_pet).response().result\n    print(f\"Added pet: {add_result.name} (ID: {add_result.id})\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n\n# Example of disabling validation for a request/response (not recommended for production)\n# client_config = {\n#     'validate_requests': False,\n#     'validate_responses': False,\n#     'use_models': False # Get dicts instead of dynamic models\n# }\n# client_relaxed = SwaggerClient.from_url(\n#     'http://petstore.swagger.io/v2/swagger.json', \n#     config=client_config\n# )\n# pet_dict = client_relaxed.pet.getPetById(petId=42).response().result\n# print(f\"Found pet as dict: {pet_dict.get('name')}\")","lang":"python","description":"Initializes a SwaggerClient from a public OpenAPI/Swagger specification URL and demonstrates a simple GET request. It also shows how to perform a POST request and mentions optional configuration to disable validation or receive responses as dictionaries instead of dynamic models."},"warnings":[{"fix":"Replace `client.operation().result()` with `client.operation().response().result`.","message":"The `HttpFuture.result()` method is deprecated. Users should now use `HttpFuture.response().result` to access the unmarshalled Swagger result, or `HttpFuture.response()` to get the full `BravadoResponse` instance which includes both the result and HTTP metadata.","severity":"deprecated","affected_versions":"All versions where `response()` exists, specifically recent versions from 1.x onwards (e.g., in documentation from 2018 onwards)."},{"fix":"Ensure your Swagger spec is valid and that your API interactions conform to it. Validation can be selectively disabled via the `config` dictionary passed to `SwaggerClient.from_url()` or `from_spec()` (e.g., `{'validate_requests': False, 'validate_responses': False, 'validate_swagger_spec': False}`).","message":"Bravado performs strict validation by default on the Swagger/OpenAPI specification itself, as well as on outgoing requests and incoming responses. This can lead to validation errors if the spec is malformed or if requests/responses don't strictly adhere to the schema.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When using an interactive Python environment (like IPython), use the `?` suffix (e.g., `client.pet.getPetById?`) to view the operation's detailed documentation, including parameters and return types.","message":"Docstrings for operations in Bravado do not behave like standard Python function docstrings and the built-in `help()` function might not work as expected. The docstrings are structured more like class docstrings.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Pass a `fallback_result` (either a static value or a callable that accepts the exception) and optionally `exceptions_to_catch` to `response()`: `client.operation().response(fallback_result=my_fallback_func, exceptions_to_catch=(BravadoTimeoutError,))`.","message":"By default, network or server errors will raise exceptions (e.g., `BravadoTimeoutError`, `HTTPServerError`). For more graceful error handling, `HttpFuture.response()` supports a `fallback_result` argument.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}