{"id":2275,"library":"schemathesis","title":"Schemathesis","description":"Schemathesis is a property-based testing framework for API specifications, primarily OpenAPI and GraphQL. It generates test cases from your schema, fuzzing inputs to find edge cases and ensure API contracts are met. Currently at version 4.15.0, it maintains an active release schedule with frequent updates and improvements.","status":"active","version":"4.15.0","language":"en","source_language":"en","source_url":"https://github.com/schemathesis/schemathesis","tags":["api testing","openapi","graphql","property-based testing","fuzzing","schema validation","contract testing"],"install":[{"cmd":"pip install schemathesis","lang":"bash","label":"Install core library"},{"cmd":"pip install schemathesis[fastapi]","lang":"bash","label":"Install with FastAPI support"},{"cmd":"pip install schemathesis[flask]","lang":"bash","label":"Install with Flask support"}],"dependencies":[],"imports":[{"note":"Used to load an API schema from a URL or file path.","symbol":"from_uri","correct":"import schemathesis; schema = schemathesis.from_uri(...)"},{"note":"Used to load an API schema from a Python dictionary.","symbol":"from_dict","correct":"import schemathesis; schema = schemathesis.from_dict(...)"},{"note":"The main programmatic method to run tests against a live API.","symbol":"test","correct":"result = schema.test(base_url='...')"},{"note":"Decorator to register custom checks for generated test cases.","symbol":"register_check","correct":"import schemathesis; @schemathesis.register_check('my_check') def my_check_function(...): ..."}],"quickstart":{"code":"import schemathesis\nimport os\n\n# For this example, we use a public OpenAPI spec and a public API endpoint.\n# In a real scenario, SCHEMA_URL would be your API's spec and API_BASE_URL\n# would be the target environment (e.g., 'http://localhost:8000').\nSCHEMA_URL = \"https://petstore.swagger.io/v2/swagger.json\"\nAPI_BASE_URL = \"https://petstore.swagger.io/v2\"\n\n# Optional: Configure authentication if your API requires it.\n# For example, with an API key in a header:\n# AUTH_HEADER_KEY = os.environ.get('MY_API_KEY_HEADER', '')\n# AUTH_HEADER_VALUE = os.environ.get('MY_API_KEY_VALUE', '')\n# custom_headers = {AUTH_HEADER_KEY: AUTH_HEADER_VALUE} if AUTH_HEADER_KEY else {}\n\ntry:\n    # Load the API schema from a URI\n    schema = schemathesis.from_uri(SCHEMA_URL)\n\n    # Run the tests against the live API.\n    # The `base_url` parameter is crucial to specify the actual API endpoint\n    # where requests will be sent. Add `headers=custom_headers` for auth.\n    result = schema.test(base_url=API_BASE_URL)\n\n    if result.is_success:\n        print(\"\\nAll Schemathesis tests passed successfully!\")\n    else:\n        print(\"\\nSchemathesis tests failed. See report for details.\")\n        # Uncomment the line below for a detailed failure report\n        # print(result.to_json())\n        exit(1) # Indicate failure in a script context\n\nexcept Exception as e:\n    print(f\"\\nAn error occurred during testing: {e}\")\n    exit(1)\n","lang":"python","description":"This quickstart demonstrates how to load an OpenAPI schema from a URI and then execute property-based tests against a live API endpoint using `schemathesis.test()`. It includes notes on specifying the API base URL and handling authentication."},"warnings":[{"fix":"Migrate your test calls from `schema.validate_response(...)` to `result = schema.test(...)`. The `test()` method returns a `TestResult` object which provides success status and detailed reports.","message":"The `schema.validate_response()` method for running tests was removed in Schemathesis v4. It has been replaced by `schema.test()`.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Review the v4 migration guide for `from_asgi`/`from_wsgi` to update function calls. Ensure you're passing the application instance or the correct import path string as `app_or_path`.","message":"The signatures for `schemathesis.from_asgi()` and `schemathesis.from_wsgi()` changed significantly in v4. The `app` parameter for the ASGI/WSGI application was renamed to `app_or_path` and its behavior was refined.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Provide authentication credentials via the `headers`, `auth`, `app_url`, or `base_url` parameters when calling `schema.test()` or `schemathesis.from_uri()`. For complex scenarios, use Schemathesis hooks to inject authentication dynamically for each request.","message":"Authentication for your API under test is often overlooked. Schemathesis by default sends requests without authentication, leading to 401/403 errors and incomplete test coverage.","severity":"gotcha","affected_versions":"all"},{"fix":"Always explicitly provide the `base_url` argument to `schema.test()` to ensure tests target the correct API environment. For `schemathesis.from_uri()`, the `base_url` can also override or provide the API base URL if the schema doesn't define it or if it points to an incorrect environment.","message":"The `base_url` parameter for `schema.test()` is critical. If not specified correctly, tests might be sent to the wrong endpoint, or if your schema lacks a `servers` field, requests might fail entirely.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}