Registry / testing / schemathesis

schemathesis

JSON →
library4.25.2pypypi✓ verified 24d ago

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.

pip install schemathesis
INSTALL
IMPORT
SIG · SCHEMATHESIS
S
schemathesis
testingpythonv4.25.2
Install
7.4s avg
Import
1381ms
Disk
74MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.25.2 · 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.915 runs
installs and imports cleanly · install 0.0s · import 1.443s · 74.5MB
glibc
py 3.103.915 runs
installs and imports cleanly · install 7.4s · import 1.319s · 75MB
74MB installed
● package 74MB
Code
Verified usage

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

schemathesis
import schemathesis
import schemathesis; schema = schemathesis.from_uri(...)

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.

import schemathesis import os # For this example, we use a public OpenAPI spec and a public API endpoint. # In a real scenario, SCHEMA_URL would be your API's spec and API_BASE_URL # would be the target environment (e.g., 'http://localhost:8000'). SCHEMA_URL = "https://petstore.swagger.io/v2/swagger.json" API_BASE_URL = "https://petstore.swagger.io/v2" # Optional: Configure authentication if your API requires it. # For example, with an API key in a header: # AUTH_HEADER_KEY = os.environ.get('MY_API_KEY_HEADER', '') # AUTH_HEADER_VALUE = os.environ.get('MY_API_KEY_VALUE', '') # custom_headers = {AUTH_HEADER_KEY: AUTH_HEADER_VALUE} if AUTH_HEADER_KEY else {} try: # Load the API schema from a URI schema = schemathesis.from_uri(SCHEMA_URL) # Run the tests against the live API. # The `base_url` parameter is crucial to specify the actual API endpoint # where requests will be sent. Add `headers=custom_headers` for auth. result = schema.test(base_url=API_BASE_URL) if result.is_success: print("\nAll Schemathesis tests passed successfully!") else: print("\nSchemathesis tests failed. See report for details.") # Uncomment the line below for a detailed failure report # print(result.to_json()) exit(1) # Indicate failure in a script context except Exception as e: print(f"\nAn error occurred during testing: {e}") exit(1)
schemathesis --version
Debug
Known issues
breakingThe `schema.validate_response()` method for running tests was removed in Schemathesis v4. It has been replaced by `schema.test()`.
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.
affects: >=4.0.0
breakingThe 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.
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`.
affects: >=4.0.0
gotchaAuthentication for your API under test is often overlooked. Schemathesis by default sends requests without authentication, leading to 401/403 errors and incomplete test coverage.
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.
affects: all
gotchaThe `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.
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.
affects: all
Upgrade
Version history
4.25.2latest on PyPI · released Aug 24, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
1
Resources
schemathesis — pip install schemathesis · libregistry