{"id":23753,"library":"flex","title":"Flex","description":"Flex is a Swagger/OpenAPI schema validation library for Python. It validates API responses against a Swagger specification. Current version is 6.14.1. Release cadence is irregular, with recent releases focusing on maintenance and compatibility updates.","status":"active","version":"6.14.1","language":"python","source_language":"en","source_url":"https://github.com/pipermerriam/flex","tags":["swagger","openapi","validation","api"],"install":[{"cmd":"pip install flex","lang":"bash","label":"Install via pip"}],"dependencies":[{"reason":"Used for parsing YAML specifications. No maximum version constraint since 6.14.0.","package":"PyYAML","optional":false},{"reason":"Dependency for JSON Schema validation, which flex uses internally.","package":"jsonschema","optional":false},{"reason":"Used for loading remote Swagger specifications.","package":"requests","optional":false}],"imports":[{"note":"Wrong: no direct submodule imports; use the top-level module.","wrong":"from flex import ...","symbol":"flex","correct":"import flex"},{"note":"Wrong: validate_api is not exposed at package root.","wrong":"flex.validate_api()","symbol":"validate_api","correct":"from flex.validation import validate_api"}],"quickstart":{"code":"import flex\nfrom flex.validation import validate_api\n\n# Load a Swagger spec from a file\nwith open('swagger.yaml', 'r') as f:\n    schema = flex.load(f)\n\n# Example API response (dict)\nresponse = {\n    'status_code': 200,\n    'headers': {'content-type': 'application/json'},\n    'body': '{\"id\": 1, \"name\": \"test\"}'\n}\n\n# Validate response against a specific path and method\ntry:\n    validate_api(schema, path='/users/{id}', method='get', response=response)\n    print('Validation passed')\nexcept flex.exceptions.Error as e:\n    print(f'Validation failed: {e}')","lang":"python","description":"Validate an API response against a Swagger specification."},"warnings":[{"fix":"Upgrade to flex >=6.14.1","message":"Flex uses collections.abc which may cause DeprecationWarning in Python 3.8+. Fixed in v6.14.1.","severity":"deprecated","affected_versions":"<6.14.1"},{"fix":"Pin PyYAML version if needed: pip install 'PyYAML<5.1'","message":"Version 6.14.0 removed maximum version constraints on dependencies (e.g., PyYAML). This may introduce incompatibilities if you rely on older versions.","severity":"breaking","affected_versions":">=6.14.0"},{"fix":"Use flex.loads() for a string, or flex.load() for an open file object.","message":"flex.load() expects a file-like object or a string, not a raw dictionary.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use: from flex.validation import validate_api","cause":"Trying to call validate_api from the top-level module, but it's in flex.validation.","error":"AttributeError: module 'flex' has no attribute 'validate_api'"},{"fix":"Ensure the path matches exactly, including parameter placeholders like {id}.","cause":"The path in the request does not match any path in the Swagger spec (or path templating mismatch).","error":"flex.exceptions.NoSuchPath: No matching path found for /api/users/1"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}