Skip to main content

Surety — contract-driven testing framework for Python. Define schemas, generate realistic test data, and validate API, database, and UI interactions with reusable Python classes.

Project description

Surety
PyPI version Python versions Downloads Tests Documentation Status License

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 typesBool, 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

surety-0.0.14.tar.gz (291.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

surety-0.0.14-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file surety-0.0.14.tar.gz.

File metadata

  • Download URL: surety-0.0.14.tar.gz
  • Upload date:
  • Size: 291.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for surety-0.0.14.tar.gz
Algorithm Hash digest
SHA256 637d359c9cc05f7f8d436dd4520da5becebfb0f9b36adb8bb11d8c75982ffbad
MD5 690964b20ea377adf356aec6f1aca9fe
BLAKE2b-256 351bfead9a2b8709e69efda81af5f7c82421061800810e9d2077800692216e8c

See more details on using hashes here.

File details

Details for the file surety-0.0.14-py3-none-any.whl.

File metadata

  • Download URL: surety-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for surety-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 99715d21653b07d093033d8534c2b1d96cda799a808d518dfc8bba8d76d7dcfc
MD5 c2f350d857b5bcf7e055c8bd7e338f9a
BLAKE2b-256 6e5b3007d8d615abe40cdfddaad88ca0f2ec974d24a223401b5967a6e137e90d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page