Skip to main content

Surp Python

Rust-backed Python bindings for Surp, a compact binary serialization format with a human-readable text notation and an additive RFC-001 CTN/CBF/CQL path.

The Python distribution is named surp and is backed by the PyO3 extension module surp._surp_native.

Install

pip install surp

From a checkout:

cd surp-python
maturin develop --release
python -m pytest tests/ -v

v1 API

import surp

payload = {
    "name": "Alice",
    "age": 30,
    "active": True,
    "avatar": b"\x01\x02\x03",
}

data = surp.dumps(payload, dedup=True, sort_keys=True)
assert surp.loads(data) == payload

Supported inputs are None, bool, int, float, str, bytes, list, tuple, and dictionaries with string keys. Tuples decode as lists.

Public helpers:

  • dumps, loads, dump, load
  • encode, decode, encode_to_file, decode_from_file
  • parse_text, pretty_print
  • to_value, loads_value, parse_text_value, SurpValue
  • Encoder, SurpDecoder

Use loads_value() or parse_text_value() when you want native-backed attribute access instead of plain Python containers:

view = surp.loads_value(data)
assert view["name"].value == "Alice"
assert view["tags"][0].value == "admin"

RFC-001 Helpers

from surp import rfc001

cbf = rfc001.compile_ctn('User\n  name = "Alice"', alignment=4)
decoded = rfc001.decode_cbf(cbf)

assert decoded["header"]["magic"] == "SURP"
assert rfc001.query_cbf(cbf, ".name", as_ctn=True) == ['"Alice"']

surp.rfc001 exposes CTN parsing/normalization, CTN-to-CBF compilation, CBF decoding, CBF-to-CTN formatting, and baseline CQL path queries.

For IDE-friendly RFC access, use the model helpers:

doc = rfc001.parse_ctn_model('User\n  name = "Alice"')
user = doc.effective_root()
assert user["name"].scalar_value == "Alice"

RFC-001 Model Schemas

surp.model provides a declarative validation layer for RFC-001 products and documents. Model classes use explicit RFC-001 type markers and encode through surp.rfc001.compile_ctn().

from surp.model import Field, SurpModel
from surp.model.types import Bool, Int64, SeqOf, Str


class User(SurpModel):
    name: Str = Field(required=True)
    age: Int64 = Field(required=False, default=0)
    active: Bool = Field(required=True)
    tags: SeqOf[Str] = Field(required=False, default_factory=list)


user = User(name="Alice", active=True, tags=["admin"])
cbf = user.to_cbf()
data = user.to_surp()
assert User.from_cbf(cbf) == user
assert User.from_surp(data) == user

Typing

The wheel includes .pyi stubs and py.typed for type checkers.

License

Licensed under either MIT or Apache-2.0, at your option.

Release files for surp 1.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 surp 1.0.2
File Size Uploaded
surp-1.0.2.tar.gz 149.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for surp 1.0.2
File Interpreter ABI Platform
surp-1.0.2-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details

Total release size: 710.5 kB

Release files / surp-1.0.2.tar.gz

Download URL surp-1.0.2.tar.gz
Size 149.9 kB
Tags Source
SHA-256 checksum
How to use checksums
20977e55f629c86a4bb12eca7afc80842e05c91cf1821dde0cb18cd0df1b6f72
BLAKE2b-256 checksum
How to use checksums
e167eb9015564f9680eb3105ce8382a13b1d4558f054263d3954a22bc162f704
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / surp-1.0.2-cp312-cp312-macosx_11_0_arm64.whl

Download URL surp-1.0.2-cp312-cp312-macosx_11_0_arm64.whl
Size 560.6 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
889db5144219b6e909c4433a8da7ca787faf6935efcfaf066e0a199786399e6e
BLAKE2b-256 checksum
How to use checksums
12b0c4ef9007627a1fc4bf7aa6e45766d41627089a8adef426f94de73fea26b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

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