Surety — Contract-Driven Testing Framework for Python
Surety makes contract-based testing simple and readable.
The surety framework replaces scattered assertions with explicit schemas and contracts — Python classes that define expected data structures, generate realistic test data, and validate real responses deterministically.
A schema is a Dictionary subclass that defines the shape of data — fields, types, and constraints. A contract adds communication semantics on top of a schema — such as an API method and path, an event name, or a database table reference.
from surety import Dictionary, String, Int, Bool
class Customer(Dictionary):
Id = Int(name='customer_id', min_val=1000, max_val=99999)
Email = String(name='email')
FirstName = String(name='first_name')
Active = Bool(name='active')
customer = Customer()
print(customer.value)
# {'customer_id': 48271, 'email': 'jane.doe@example.com', 'first_name': 'Margaret', 'active': True}
Features
Schema-first — define expected data structures as reusable Python classes, not scattered assertions
Contracts — bind schemas to communication semantics (API endpoints, database tables, events)
Data generation — auto-generate realistic test data using Faker with 80+ providers
Transport-agnostic — the same schema validates API responses, database records, and UI state
Structured diffs — precise mismatch reporting with custom comparison rules (via surety-diff)
API testing — HTTP contracts, schema-based mocking, and request verification (via surety-api)
UI testing — Selenium-based browser automation with page objects (via surety-ui)
Database testing — PostgreSQL, MySQL, SQLite, and Cassandra support (via surety-db)
Field types — Bool, Int, Float, Decimal, String, Uuid, DateTime, Enum, Array, and more
Extensible — create custom field types, comparison rules, and execution adapters
Python 3.7+ compatible
Install
pip install surety
Optional extensions:
pip install surety-diff # Structured comparison engine
pip install surety-api # HTTP API interaction and mocking
pip install surety-ui # Browser-based UI testing with Selenium
pip install surety-db # Database interaction layer
pip install surety-config # YAML-based configuration
Quick Example
Define a schema, generate data, and validate:
from surety import Dictionary, String, Int, Array
from surety.diff import compare
# Define schemas
class Address(Dictionary):
City = String(name='city')
ZipCode = String(name='zip_code', fake_as='zipcode')
class Order(Dictionary):
Id = Int(name='order_id')
Status = String(name='status', default='pending')
ShippingAddress = Address(name='shipping_address')
# Generate test data
order = Order()
print(order.value)
# {'order_id': 7312, 'status': 'pending', 'shipping_address': {'city': 'Portland', 'zip_code': '97201'}}
# Validate against actual response
compare(actual=api_response, expected=order.value)
Override specific values while keeping the rest auto-generated:
order = Order().with_values({
Order.Id.name: 1,
Order.ShippingAddress.name: {Address.City.name: 'Seattle'}
})
Use comparison rules for dynamic fields:
from surety.diff import compare
from surety.diff.rules import has_some_value, timestamp_equal_with_delta_3s
compare(
actual=response,
expected=order.value,
rules={
Order.Id.name: has_some_value,
Order.CreatedAt.name: timestamp_equal_with_delta_3s
}
)
Architecture
Surety separates three concerns:
Schemas |
surety |
Define data structures and generate test data |
Contracts & Execution |
surety-api, surety-db, surety-ui |
Bind schemas to endpoints, tables, and pages; perform interactions |
Validation |
surety-diff |
Compare actual data against schemas |
Documentation
Full documentation: https://surety.readthedocs.io/
Issues
Report bugs and feature requests at the issue tracker.
License
MIT License. See LICENSE for details.
Copyright (c) 2026 Elena Kulgavaya.
Metadata
Release files for surety 0.0.29
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| surety-0.0.29.tar.gz | 295.8 kB | Without provenance | Details for surety-0.0.29.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| surety-0.0.29-py3-none-any.whl | Python 3 | none | any | Details for surety-0.0.29-py3-none-any.whl |
Total release size: 315.9 kB
Release files / surety-0.0.29.tar.gz
| Download URL | surety-0.0.29.tar.gz |
|---|---|
| Size | 295.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ffd605f727e53dc3c2a5f022c34aa084f0bfc0cfd247e1220224bd5e9ef3ad98
|
|
BLAKE2b-256 checksum How to use checksums |
8065b81eed00b3cf8fef56f00532957da9ff8b89afb092da7532e3afaa1d9143
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / surety-0.0.29-py3-none-any.whl
| Download URL | surety-0.0.29-py3-none-any.whl |
|---|---|
| Size | 20.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5bd6a77f73afac56fbac962bc0e8c950d212f16615ad2af1a72396246edc24e2
|
|
BLAKE2b-256 checksum How to use checksums |
8e44e6eaf6f2f6eba857c84adbc860d61b9d71ceb27e3f4d42296d414ae9e954
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for surety 0.0.29
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.