Skip to main content

surety-scaffold

Code generation toolkit for the surety contract-testing framework.

Bootstraps surety schemas, contracts, callers, and test scaffolding from existing JSON payloads, JSON Schema, and OpenAPI specs — so you can start contract-based testing without writing boilerplate by hand.


Installation

pip install surety-scaffold

Requires surety>=0.0.4.


Features

Extract contract from JSON

Turn a raw JSON payload into surety Dictionary class definitions.

Programmatic:

import json
from surety.scaffold import extract_from_json

payload = json.dumps({
    "order_id": 42,
    "status": "pending",
    "total": 199.99,
    "is_express": False,
    "customer": {
        "customer_id": 7,
        "email": "jane@example.com"
    },
    "items": [
        {"sku": "ABC-1", "qty": 2}
    ]
})

print(extract_from_json(payload, class_name="Order"))

Output:

from surety import Array, Bool, Dictionary, Float, Int, String


class Customer(Dictionary):
    CustomerId = Int(name='customer_id', required=True)
    Email = String(name='email', required=True)


class Items(Dictionary):
    Sku = String(name='sku', required=True)
    Qty = Int(name='qty', required=True)


class Order(Dictionary):
    OrderId = Int(name='order_id', required=True)
    Status = String(name='status', required=True)
    Total = Float(name='total', required=True)
    IsExpress = Bool(name='is_express', required=True)
    Customer = Customer(name='customer', required=True)
    Items = Array(Items, name='items', required=True)

Type inference rules:

JSON value Surety type
true / false Bool
integer Int
float Float
UUID string Uuid
ISO 8601 datetime or date string DateTime
any other string String
object {} nested Dictionary subclass
array of objects Array(NestedClass, ...)
array of primitives Array(PrimitiveType, ...)
null String(allow_none=True)

Nested objects produce their own Dictionary subclass and are always emitted before the class that references them. Arrays of objects merge all items across the array to capture the full set of fields. Duplicate class names (same key appearing at different nesting levels) are disambiguated automatically with a numeric suffix.

Key naming: JSON keys are converted to PascalCase for both the class attribute name and the generated class name. snake_case, camelCase, and kebab-case are all handled.


CLI:

# Pass JSON as an argument
surety-scaffold '{"order_id": 1, "status": "pending"}' --class-name Order

# Pipe from a file or command
cat response.json | surety-scaffold --class-name Order

# Skip clipboard copy
surety-scaffold '{"x": 1}' --no-clipboard

The result is printed to stdout and automatically copied to the clipboard (pbcopy on macOS, xclip on Linux).

usage: surety-scaffold [-h] [--class-name CLASS_NAME] [--no-clipboard] [json]

positional arguments:
  json                  JSON string to extract from. Reads from stdin if omitted.

options:
  --class-name, -c      Name for the top-level generated class (default: Schema).
  --no-clipboard        Do not copy the result to the clipboard.

Roadmap

The following features are planned for this library. They complement the core surety framework with static analysis, code generation, and developer tooling.

In scope for surety-scaffold

# Feature Status
1 Extract contract from JSON — infer surety schemas from raw API responses done
4 Parse JSON Schema / OpenAPI — generate surety Dictionary classes from JSON Schema or OpenAPI 3.x specs, resolving $ref and mapping constraints planned
5 Generate callers — produce ApiContract boilerplate and caller function stubs from OpenAPI operations planned
12 Generate test scenarios (basic) — scaffold positive pytest test cases (required fields, full fields, with_values overrides) for a given contract planned

Release files for surety-scaffold 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for surety-scaffold 0.0.2
File Size Uploaded
surety_scaffold-0.0.2.tar.gz 18.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for surety-scaffold 0.0.2
File Interpreter ABI Platform
surety_scaffold-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 27.6 kB

Release files / surety_scaffold-0.0.2.tar.gz

Download URL surety_scaffold-0.0.2.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6e873edc46541d4a8cb377f582c731aeef5e5968c50a7e944943f1df4b1f0ac4
BLAKE2b-256 checksum
How to use checksums
cdaa5527d6b5f7a42610c806748b848357ee68a6aaeda2decff9f9bf01ced63d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / surety_scaffold-0.0.2-py3-none-any.whl

Download URL surety_scaffold-0.0.2-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a6596396f76dc57bc751a21d07da8cf8888737fdda7fb777cafeff2ca6503e0d
BLAKE2b-256 checksum
How to use checksums
c9687bc4bfde6bbe54e311a7f110f17574ceb4b9920c3253dcbe8046caf905d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page