Skip to main content

Work with Clarity smart contract values in Python

Project description

pyclarity-values

A Python library for working with Clarity smart contract values on the Stacks blockchain. Supports full serialization/deserialization of all Clarity types, including principals, lists, tuples, strings, optional and response types.


Features

  • ✅ Deserialize raw Clarity bytes
  • ✅ Serialize Clarity types into bytes
  • ✅ Conversion between human-readable principals and hash160
  • ✅ Support for all Clarity types
  • ✅ Minimal and type-safe core

Installation

pip install pyclarity-values

Or from source:

git clone https://github.com/allbridge-io/pyclarity-values.git
cd pyclarity-values
pip install .

Usage

from clarity import deserialize_cv, serialize_cv, principal_cv, address_to_string
from clarity import UIntCV, StandardPrincipalCV, Address

# Deserialize UInt
cv = deserialize_cv(bytes.fromhex("0100000000000000000000000000002a"))
print(cv.value)  # 42

# Serialize back
print(serialize_cv(cv).hex())  # 0100000000000000000000000000002a

# Principals
addr = Address(type=1, version=22, hash160="c34898bb416add50607c973b125560d31c07fd1b")
cv = StandardPrincipalCV(addr)
print(serialize_cv(cv).hex())  # 0516c348...
print(address_to_string(addr))  # SP31MH65V85NDTM30FJBKP4JNC39HR1ZX3CRW9Z97

# From principal string
cv = principal_cv("SP31MH65V85NDTM30FJBKP4JNC39HR1ZX3CRW9Z97.bridge")
print(serialize_cv(cv).hex())

Supported Clarity Types

  • IntCV, UIntCV
  • BufferCV, StringAsciiCV, StringUtf8CV
  • BooleanCV
  • OptionalCV, SomeCV, NoneCV
  • ResponseOkCV, ResponseErrorCV
  • ListCV, TupleCV
  • StandardPrincipalCV, ContractPrincipalCV

License

MIT

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

pyclarity_values-0.1.0.tar.gz (16.4 kB view details)

Uploaded Source

Built Distribution

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

pyclarity_values-0.1.0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file pyclarity_values-0.1.0.tar.gz.

File metadata

  • Download URL: pyclarity_values-0.1.0.tar.gz
  • Upload date:
  • Size: 16.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for pyclarity_values-0.1.0.tar.gz
Algorithm Hash digest
SHA256 45f2e091c00f177ee2dbc1e8c6ccdbaec2fc8b5dadead193421f90c01f1a45fe
MD5 892f5066549f950a1791a18f18724fa5
BLAKE2b-256 16ff6f2b29242dbabe357307d5c859f6ab11e282e020928a8f229dc852a7c676

See more details on using hashes here.

File details

Details for the file pyclarity_values-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pyclarity_values-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 370959de8c0743de9be4c9554bd9d2189e7722f5e2721ebbbda19280b428eefa
MD5 4aae18d4bcf8d2a936f64387ebe38a15
BLAKE2b-256 41c22ecb744b338ceaffd778d028598f2336b80f0f334df2a06c46e3d2ab76f9

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