Skip to main content

xian-tech-runtime-types

Shared deterministic runtime types for the Xian stack.

Contents

  • decimal.py: fixed-precision ContractingDecimal and decimal bounds
  • time.py: deterministic Datetime and Timedelta
  • collections.py: deterministic set and frozenset implementations
  • encoding.py: JSON encoding/decoding for runtime storage values

These types are used by xian-contracting and other packages that need the same deterministic value semantics without importing the full contract runtime.

The encoder and convert_dict normalize nested lists and dictionaries recursively. Large integers use __big_int__ at every depth; booleans retain their JSON type.

Fresh-genesis numbers

The public encoder and decoder APIs default to xian_vm_v2. Use encode_wire for SDK and transaction JSON and encode / decode for stored values. Select vm_profile="xian_vm_v1" explicitly for historical state. Bare JSON integers range from -(2**53 - 1) to 2**53 - 1. Larger magnitudes use a canonical signed decimal string under __big_int__, with magnitude below 2**512. Decimals use {"__fixed__": "1.25"} at every depth. Wire spelling uses plain ASCII digits, a leading minus for negative values, and no redundant zeros. The smallest unit is 10**-30 and the absolute value must be below 10**61. canonical_fixed converts exact Python decimal values, strings and integers to this form. Binary float, nonfinite values and unrepresentable input fail.

normalize_wire_numbers turns typed input into a JSON tree, and loads_wire_json parses incoming JSON while retaining its tags and rejecting noncanonical numeric tokens such as -0, 1.0 and 1e-400. decode_wire_numbers checks and decodes the resulting wire tree. Numeric tags already supplied as JSON must be canonical. V2 stored dictionaries and wire objects use string keys. Numeric members of the existing versioned set codec support integers and fixed decimals. V2 sets preserve distinct boolean and integer members, including inside tuples and nested frozen sets.

For off-chain contract arguments, construct Python int and decimal.Decimal values from integers or strings and pass them through the current codecs. str() and repr() of a ContractingDecimal give the same plain fixed-point text as canonical_fixed and the V2 VM's str(decimal): no exponent, no trailing fractional zeros, 0 for zero (1000, not 1E+3). Format specs such as f"{amount:.4f}" apply to that plain value as V2 format(decimal, spec) does. ContractingDecimal and the wrapper collection classes also implement legacy CPython operations for archival replay. The native VM executes V2 contract arithmetic and determines the types returned to the client.

Validation

The package is covered by the root test suite:

uv run pytest -q tests/unit/test_decimal.py tests/unit/test_datetime.py \
  tests/unit/test_timedelta.py tests/unit/test_contracting_collections.py \
  tests/unit/test_encode.py tests/unit/test_set_codec.py tests/unit/test_wire_encoding.py

Persistent wrapper sets (xian-set-1)

New ContractingSet and ContractingFrozenSet writes retain the outer __set__ / __frozenset__ tag and contain an explicit member envelope:

{"__set__":{"codec":"xian-set-1","items":[["tuple",[["int","1"],["int","2"]]]]}}

Members use a closed typed grammar. V2 supports the following member tags, with two additional historical tags available only through explicit V1 decoding.

Node Payload
["none"] No payload
["bool", value] JSON boolean
["int", digits] Canonical signed decimal integer string
["float", bits] V1 only. Exactly 16 lowercase hexadecimal IEEE754 binary64 bits
["fixed", scaled] Canonical integer string at the existing 10**30 scale
["raw_decimal", sign, digits, exponent] V1 only. Sign 0/1, unsigned coefficient string, exact base-10 exponent
["str", text] Unicode scalar string
["bytes", hex] Lowercase hexadecimal byte string
["datetime", parts] Year, month, day, hour, minute, second, microsecond
["timedelta", seconds] Canonical signed integer seconds string
["tuple", members] Typed child nodes
["frozenset", members] Canonically ordered typed child nodes

Mutable sets, lists, mappings, callables, proxies and non-finite numbers cannot be members. The existing deterministic wrapper normalization defines order and deduplication; decoding rejects noncanonical new envelopes instead of silently rewriting them. Ordinary scalar/container encodings outside wrapper sets retain their existing representation.

The codec bounds each wrapper payload to depth 64, 131,072 typed nodes and an 8 MiB conservative JSON byte cap, measured with Python-compatible ASCII escapes. Astral characters count as two six-byte surrogate escapes for this cap. The VM's metering representation remains compact UTF-8 JSON, so this conservative cap is not the gas byte-count formula. Existing transaction/write limits can be stricter. V2 integer members have at most 512 bits of magnitude. In V1, the integer limit is 1,048,576 bits and raw Decimal digits, canonical text and absolute exponent are bounded by 131,072. The sum of squared cardinalities of every wrapper set/frozen set in one persistence payload must not exceed 8,388,608, checked before normalization. A single set can therefore contain at most 2,896 members; nesting and multiple wrapper roots share that work budget. Explicit V1 decoding shares the same budget across object-hook constructions without counting an already reconstructed nested wrapper twice.

Before serialization, encode, Encoder and validate_persistent_value also bound the ordinary value tree to depth 128 (root depth zero) and 1,048,576 visited values. Dictionary keys and values count separately, and repeated references count at each occurrence. Wrapper sets use the separate member limits above. This validation rejects cycles, non-finite numbers and reserved dictionary tags even when a payload contains no sets. SDK transaction kwargs that use this encoder receive the same checks before signing.

These serializer ceilings do not guarantee node acceptance. The node checks depth 128 on the complete transaction JSON, including its outer envelope; the VM independently bounds external values to depth 128 and 131,072 visited values. Transaction sizes, execution budgets and storage limits also apply.

Select V1 to read a legacy list-shaped set envelope. Arrays that occur as legacy set members are restored recursively as tuples; ordinary JSON arrays elsewhere remain lists. Legacy __fixed__ values retain their historical fixed type because old writes cannot recover already-lost raw Decimal quantum.

The public helpers exported by xian_runtime_types.encoding are:

  • is_wrapper_set(value) identifies the deterministic wrapper families.
  • encode_set_value(value) returns a plain versioned JSON object.
  • decode_set_value(tag, payload) reads the typed V2 envelope. Pass exact_numbers=False to either set helper for the historical V1 representation.
  • validate_persistent_value(value) checks finite values, bounded traversal, cycles, unsupported objects and reserved-key collisions before serialization.

New ordinary persisted dictionaries cannot contain any reserved runtime codec key, even with siblings or inside another container. This covers every key in encoding.TYPES, not just set tags. Actual typed objects remain valid. Trusted wire data must be decoded with decode/convert_dict before re-encoding; feeding an already-tagged ordinary dictionary to encode intentionally fails. Explicit V1 reads retain historical tag recognition.

Wire documents and persistent values

Use encode_wire(value) for transaction kwargs, envelopes and genesis/config documents that may already contain canonical codec tags. A tagged value must use the complete representation for its type. The default V2 decoder rejects malformed wrappers, alternate numeric spellings and extra sibling keys.

Use encode(value), Encoder or validate_persistent_value when working with typed storage and effect values. They reject ordinary dictionaries that contain reserved codec keys. Both storage and transaction objects require string keys. For an archived V1 document, select vm_profile="xian_vm_v1" explicitly. Its historical wire encoder preserves opaque tags and its decoder accepts legacy set-array representations.

Metadata

Release files for xian-tech-runtime-types 0.1.6

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

Source distribution (sdist)

Source distribution for xian-tech-runtime-types 0.1.6
File Size Uploaded Provenance Actions
xian_tech_runtime_types-0.1.6.tar.gz 24.9 kB With provenance Details for xian_tech_runtime_types-0.1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for xian-tech-runtime-types 0.1.6
File Interpreter ABI Platform Actions
xian_tech_runtime_types-0.1.6-py3-none-any.whl Python 3 none any Details for xian_tech_runtime_types-0.1.6-py3-none-any.whl

Total release size: 49.7 kB

Release files / xian_tech_runtime_types-0.1.6.tar.gz

Download URL xian_tech_runtime_types-0.1.6.tar.gz
Size 24.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b331be40daf4549655164a92bce0c8c805e13de398849d6140029e257ef47d91
BLAKE2b-256 checksum
How to use checksums
28b18fb1ec04d5efa26116573553f323a130a7c0479d1d931eb3b88bf3ca474a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / xian_tech_runtime_types-0.1.6-py3-none-any.whl

Download URL xian_tech_runtime_types-0.1.6-py3-none-any.whl
Size 24.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0a9884d842d04133dc62df53a8d5b6916853b36435546535d949d02f535e76f1
BLAKE2b-256 checksum
How to use checksums
6b8263ab179fe3b72ac5e921bb02950efa76b8ff45c8d31d1b83314823687602
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Security for xian-tech-runtime-types 0.1.6

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for xian_tech_runtime_types-0.1.6.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

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.

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