Skip to main content

Quick Borsh (qborsh)

An optimized Borsh (Binary Object Representation Serializer for Hashing) library for Python, written in C.

Install

pip install qborsh

Usage

Type Encoding/Decoding

import qborsh

encoded = qborsh.String.encode("Hello world!")
decoded = qborsh.String.decode(encoded)

array_of_u8s = qborsh.Array[qborsh.U8, 5]
encoded = array_of_u8s.encode([1, 2, 3, 4, 5])
decoded = array_of_u8s.decode(encoded)

Schema Encoding/Decoding

import qborsh

@qborsh.schema
class Example:
    # Numeric types
    u8_int: qborsh.U8
    u16_int: qborsh.U16
    u32_int: qborsh.U32
    u64_int: qborsh.U64
    u128_int: qborsh.U128
    i8_int: qborsh.I8
    i16_int: qborsh.I16
    i32_int: qborsh.I32
    i64_int: qborsh.I64
    i128_int: qborsh.I128
    f32_float: qborsh.F32
    f64_float: qborsh.F64

    # Bool, String, Bytes
    bool_val: qborsh.Bool
    string_val: qborsh.String
    bytes_val: qborsh.Bytes

    # Optionals
    optional_val: qborsh.Optional[qborsh.U32]

    # Collections
    set_val: qborsh.Set[qborsh.U8]
    vector_val: qborsh.Vector[qborsh.U16]
    array_val: qborsh.Array[qborsh.U8, 5]
    map_val: qborsh.Map[qborsh.U8, qborsh.String]

    # Helpers
    pubkey: qborsh.PubKey # Solana Base58 Encoded PubKey
    padding: qborsh.Padding[qborsh.Array[qborsh.U8, 10]]

@qborsh.schema
class ExampleNested:
    example: Example

data = {
    "u8_int": 255,
    "u16_int": 65535,
    "u32_int": 4294967295,
    "u64_int": 18446744073709551615,
    "u128_int": 340282366920938463463374607431768211455,
    "i8_int": -128,
    "i16_int": -32768,
    "i32_int": -2147483648,
    "i64_int": -9223372036854775808,
    "i128_int": -170141183460469231731687303715884105728,
    "f32_float": 3.4028234663852886e38,
    "f64_float": 1.7976931348623157e308,
    "bool_val": True,
    "string_val": "Hello, World!",
    "bytes_val": b"Hello, World!",
    "optional_val": 42,
    "set_val": {1, 2, 3, 4, 5},
    "vector_val": [1, 2, 3, 4, 5],
    "array_val": [1, 2, 3, 4, 5],
    "map_val": {1: "one", 2: "two", 3: "three"},
    "pubkey": "B62qoNf6QJk9kXJfzr6z7Z1J6VrYv6bQfMz7zD7c5Z9M",
    # Does not matter. Can be any value, or not present at all during
    # serialization. Must be present during deserialization however.
    "padding": "Does not matter. This is padding. Will write 0s.",
}

encoded = ExampleNested.encode({"example": data})
decoded = ExampleNested.decode(encoded)

# You may also do:
encoded = ExampleNested(example=data)   # kwargs resolve to encoding.
decoded = ExampleNested(encoded)        # args resolve to decoding.

There are three params to qborsh.schema (defaults in code-block below):

import qborsh

@qborsh.schema(
    validate: bool = False,
    dotdict: bool = False,
    exact_size: bool = True
)
class Example:
    ...
  • validate: Validate data keys during serialization. Checks if there are missing or extra keys when encoding only.
  • dotdict: Convert decoded dict into a dict with dot access for keys.
  • exact_size: If True, will return None when sizeof() is called and the schema has variable-sized field(s).

Package Wide Configuration

Buffer Size

The default size (in bytes) of buffers used throughout qborsh. If you expect very large or very small payloads, you may wish to adjust this. A too-small buffer may lead to more frequent resizing; a too-large buffer may waste memory on small payloads. Defaults to 512.

import qborsh

qborsh.set_buffer_size(1024)

or using environment variables:

QBORSH_BUFFER_SIZE=1024

Global Buffer

Whether to use a global buffer for faster serialization/deserialization. Enabling this can reduce repeated allocations in the underlying C layer, providing up to ~20-40% speedup in small- and medium-sized schemas. For large schemas, the gain is smaller but still measurable. This is not thread-safe. Defaults to True.

import qborsh

qborsh.set_global_buffer(False)

or using environment variables:

QBORSH_GLOBAL_BUFFER=False

Validate

Whether to enable validation (range checks) in the C extension. Defaults to True.

import qborsh

qborsh.set_validate(False)

or using environment variables:

QBORSH_VALIDATE=False

Benchmark

Comparing with another Python qborsh library:

Note that 'without val' means without schema validation.

--- Schema: Simple ---
borsh-construct         => avg: 258.0539 ms (std: 3.5250 ms)
qborsh (with val)       => avg: 36.9735 ms (std: 0.3608 ms)
qborsh (without val)    => avg: 36.1387 ms (std: 1.8255 ms)

--- Schema: Medium ---
borsh-construct         => avg: 334.0135 ms (std: 2.8085 ms)
qborsh (with val)       => avg: 36.2419 ms (std: 0.7954 ms)
qborsh (without val)    => avg: 36.5602 ms (std: 0.4150 ms)

--- Schema: Large ---
borsh-construct         => avg: 641.5983 ms (std: 21.6217 ms)
qborsh (with val)       => avg: 80.2482 ms (std: 2.8515 ms)
qborsh (without val)    => avg: 67.7815 ms (std: 2.1862 ms)

See scripts/benchmark.py for benchmarking details.

Metadata

Release files for qborsh 1.0.1

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

Source distribution (sdist)

Source distribution for qborsh 1.0.1
File Size Uploaded
qborsh-1.0.1.tar.gz 23.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for qborsh 1.0.1
File
qborsh-1.0.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl PyPy 3.10 PyPy 3.10 7.3 Linux glibc 2.17+ x86-64 Details
qborsh-1.0.1-cp313-cp313-musllinux_1_2_x86_64.whl CPython 3.13 CPython 3.13 Linux musl 1.2+ x86-64 Details
qborsh-1.0.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
qborsh-1.0.1-cp312-cp312-musllinux_1_2_x86_64.whl CPython 3.12 CPython 3.12 Linux musl 1.2+ x86-64 Details
qborsh-1.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
qborsh-1.0.1-cp311-cp311-musllinux_1_2_x86_64.whl CPython 3.11 CPython 3.11 Linux musl 1.2+ x86-64 Details
qborsh-1.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
qborsh-1.0.1-cp310-cp310-musllinux_1_2_x86_64.whl CPython 3.10 CPython 3.10 Linux musl 1.2+ x86-64 Details
qborsh-1.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details

Total release size: 917.3 kB

Release files / qborsh-1.0.1.tar.gz

Download URL qborsh-1.0.1.tar.gz
Size 23.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a8376bdefbfb9f920fd1a4a9dac34ff0f2b7ae110601e759f1119753a8f0e17b
BLAKE2b-256 checksum
How to use checksums
fd6be643b032df794ec58593c8f22f9db54f817572fd0a878197d1014c5552a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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 Jan 19, 2025.

Transparency log

Release files / qborsh-1.0.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL qborsh-1.0.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 44.4 kB
Tags Linux glibc 2.17+ x86-64 PyPy 3.10 PyPy 3.10 7.3
SHA-256 checksum
How to use checksums
818c26feaa701c04a98b1e28b86680b2f9421e599fbfcc117aee0fa962fb1575
BLAKE2b-256 checksum
How to use checksums
2cddaf8c2805eecab81b46e1e39c3c81c72f54b9c3e8a1a1724687f7c0488cba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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 Jan 19, 2025.

Transparency log

Release files / qborsh-1.0.1-cp313-cp313-musllinux_1_2_x86_64.whl

Download URL qborsh-1.0.1-cp313-cp313-musllinux_1_2_x86_64.whl
Size 119.1 kB
Tags CPython 3.13 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
7cbe42ac4e5c871bf36024225ec33d74b4ec2930dd1fbe8fe6c077bdb95a8db4
BLAKE2b-256 checksum
How to use checksums
72b830bc3fb36c5abc3902476f97080eea4b094d7ca5a9930ea767662376d295
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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 Jan 19, 2025.

Transparency log

Release files / qborsh-1.0.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL qborsh-1.0.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 93.1 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
b17702388d9bfd60e66b49710fa936cd211188c465e5e40ca82b093178c63d70
BLAKE2b-256 checksum
How to use checksums
7d3824b6227c0635e64da47b7096cc5f69ba457ce0bf9afb9ed9ae063f1d355f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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 Jan 19, 2025.

Transparency log

Release files / qborsh-1.0.1-cp312-cp312-musllinux_1_2_x86_64.whl

Download URL qborsh-1.0.1-cp312-cp312-musllinux_1_2_x86_64.whl
Size 119.1 kB
Tags CPython 3.12 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
890c40eea4bf18257d0e2e240a84d2723d72de4403bf2f5a18bdca7ade09750e
BLAKE2b-256 checksum
How to use checksums
8d208fc26f1f2024f20196e646e6d7d4c2fe9e3e81d9d9353d88c537844ed108
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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 Jan 19, 2025.

Transparency log

Release files / qborsh-1.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL qborsh-1.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 93.2 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
6d42f6553b5bf251ac69432cecbe6013cfa44290c1c4cc14b7d2315f37fd7f0a
BLAKE2b-256 checksum
How to use checksums
0a271625dd741692953d5d128b49de51a02d34fa2f6eb360b21abcdc21eb2d1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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 Jan 19, 2025.

Transparency log

Release files / qborsh-1.0.1-cp311-cp311-musllinux_1_2_x86_64.whl

Download URL qborsh-1.0.1-cp311-cp311-musllinux_1_2_x86_64.whl
Size 119.8 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
e76d42a049e1ce66815a01f52339cd381944cefbdf620608e7b9092be0a9e03d
BLAKE2b-256 checksum
How to use checksums
6a58583d198133f126b7e447a1a56ddf1034ef36f481755fc6ecfbed3d2c1c14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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 Jan 19, 2025.

Transparency log

Release files / qborsh-1.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL qborsh-1.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 93.4 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
9c77f2221606c0ec74493e5f2b0d23940bd05e106284866d181f04464d5705cc
BLAKE2b-256 checksum
How to use checksums
e019624061d3c1be91cec07b0501a7daad431059a6a8ffbfc07a0be913112c86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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 Jan 19, 2025.

Transparency log

Release files / qborsh-1.0.1-cp310-cp310-musllinux_1_2_x86_64.whl

Download URL qborsh-1.0.1-cp310-cp310-musllinux_1_2_x86_64.whl
Size 118.9 kB
Tags CPython 3.10 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
f9305efee15fa54489a3831be414b84abeb73783003b4dc713c540316f308285
BLAKE2b-256 checksum
How to use checksums
dbe208c3a4818f9d9c57efe8df25f3e786146b46b51195d40adb6112d7a29af9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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 Jan 19, 2025.

Transparency log

Release files / qborsh-1.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL qborsh-1.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 92.5 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
e9935243a9f9fe9ebd259ae9824c8aaf43a3ff616876a510373ef38f41c32b21
BLAKE2b-256 checksum
How to use checksums
76b18f8e01b26278aca5dac5c579605d3820069381e998c2cb5ba24a911c48be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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 Jan 19, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.1 This release

10 release files

1.0.0

10 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