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,loadencode,decode,encode_to_file,decode_from_fileparse_text,pretty_printto_value,loads_value,parse_text_value,SurpValueEncoder,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.
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| surp-1.0.2.tar.gz | 149.9 kB | Without provenance | Details for surp-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| surp-1.0.2-cp312-cp312-macosx_11_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 11.0+ ARM64 | Details for surp-1.0.2-cp312-cp312-macosx_11_0_arm64.whl |
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
|
Security for surp 1.0.2
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.