Skip to main content

Python bindings for the wincode serialization library with zerocopy support

Project description

association

I am not associated with the wincode or bincode teams. I am just a fan who needs to use it in python and wants to give others the ability to do the same. If there are any adjustments that you feel need to be made then go to wincode

pywincode

Python bindings for the wincode Rust serialization library with zerocopy support.

What is pywincode?

pywincode provides fast binary serialization and deserialization for Python, powered by Rust. It wraps the wincode library (a fast bincode implementation with placement initialization) and adds zerocopy functionality for efficient memory access without copying data.

Key Features

  • Fast serialization: Rust-powered binary serialization compatible with bincode format
  • Zero-copy arrays: Access binary data as typed arrays without memory copies
  • Type-safe: Explicit serialization functions for all primitive types
  • NumPy compatible: Zero-copy arrays work seamlessly with NumPy

Installation

pip install pywincode

From Source

# Clone the repository
git clone https://github.com/LecherousCthulhu/pywincode.git
cd pywincode

# Create virtual environment
python -m venv .venv
.venv\Scripts\Activate.ps1  # Windows
# or: source .venv/bin/activate  # Linux/macOS

# Install with maturin
pip install maturin
maturin develop --release

Quick Start

Basic Serialization

import pywincode

# Serialize bytes
data = b"hello world"
serialized = pywincode.serialize(data)
deserialized = pywincode.deserialize(serialized)
assert deserialized == data

Primitive Types

import pywincode

# Integers
serialized = pywincode.serialize_u64(12345678)
value = pywincode.deserialize_u64(serialized)

# Floats
serialized = pywincode.serialize_f64(3.14159)
value = pywincode.deserialize_f64(serialized)

# Strings
serialized = pywincode.serialize_string("hello")
text = pywincode.deserialize_string(serialized)

Zero-Copy Arrays

import struct
import pywincode

# Create binary data (10 u32 values)
values = list(range(10))
data = struct.pack(f"<{len(values)}I", *values)

# Get zero-copy view as u32 array
arr = pywincode.zerocopy_u32_array(data)
print(list(arr))  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

# Works with NumPy
import numpy as np
np_arr = np.asarray(arr)
print(np_arr.dtype)  # uint32

Lists

import pywincode

# Serialize list of bytes
items = [b"hello", b"world"]
serialized = pywincode.serialize_bytes_list(items)
result = pywincode.deserialize_bytes_list(serialized)

# Serialize list of u64
numbers = [1, 2, 3, 1000000]
serialized = pywincode.serialize_u64_list(numbers)
result = pywincode.deserialize_u64_list(serialized)

API Reference

Core Functions

Function Description
serialize(data: bytes) -> bytes Serialize bytes to wincode format
deserialize(data: bytes) -> bytes Deserialize bytes from wincode format
serialized_size(data: bytes) -> int Get serialized size without serializing
serialize_into(data: bytes, buffer: bytearray) -> int Serialize into pre-allocated buffer

Primitive Serialization

Unsigned integers: serialize_u8, serialize_u16, serialize_u32, serialize_u64 Signed integers: serialize_i8, serialize_i16, serialize_i32, serialize_i64 Floats: serialize_f32, serialize_f64 Boolean: serialize_bool String: serialize_string

Each has a corresponding deserialize_* function.

Zero-Copy Operations

Function Description
zerocopy_view(data: bytes) -> memoryview Create read-only view of bytes
zerocopy_u8_array(data: bytes) -> list[int] View bytes as u8 array
zerocopy_u16_array(data: bytes) -> list[int] View bytes as u16 array
zerocopy_u32_array(data: bytes) -> list[int] View bytes as u32 array
zerocopy_u64_array(data: bytes) -> list[int] View bytes as u64 array
zerocopy_i8_array(data: bytes) -> list[int] View bytes as i8 array
zerocopy_i16_array(data: bytes) -> list[int] View bytes as i16 array
zerocopy_i32_array(data: bytes) -> list[int] View bytes as i32 array
zerocopy_i64_array(data: bytes) -> list[int] View bytes as i64 array
zerocopy_f32_array(data: bytes) -> list[float] View bytes as f32 array
zerocopy_f64_array(data: bytes) -> list[float] View bytes as f64 array

Type Conversions

Function Description
u32_from_bytes(data: bytes) -> int Convert 4 bytes to u32
u64_from_bytes(data: bytes) -> int Convert 8 bytes to u64
f32_from_bytes(data: bytes) -> float Convert 4 bytes to f32
f64_from_bytes(data: bytes) -> float Convert 8 bytes to f64
u32_into_bytes(value: int) -> bytes Convert u32 to 4 bytes
u64_into_bytes(value: int) -> bytes Convert u64 to 8 bytes
f32_into_bytes(value: float) -> bytes Convert f32 to 4 bytes
f64_into_bytes(value: float) -> bytes Convert f64 to 8 bytes

Error Handling

All functions may raise pywincode.WincodeError on failure:

import pywincode

try:
    pywincode.deserialize(b"\xff\xff\xff\xff")
except pywincode.WincodeError as e:
    print(f"Deserialization failed: {e}")

Development

Prerequisites

  • Python 3.10+
  • Rust 1.85+
  • maturin

Building

# Windows
.\scripts\run_all.ps1

# Linux/macOS
./scripts/run_all.sh

Running Tests

# Rust tests
cargo test

# Python tests
python -m pytest tests/ -v

License

MIT License - see LICENSE for details.

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

pywincode-0.1.0.tar.gz (25.1 kB view details)

Uploaded Source

Built Distributions

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

pywincode-0.1.0-cp313-cp313-win_amd64.whl (126.2 kB view details)

Uploaded CPython 3.13Windows x86-64

pywincode-0.1.0-cp313-cp313-musllinux_1_2_x86_64.whl (422.9 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

pywincode-0.1.0-cp313-cp313-musllinux_1_2_aarch64.whl (386.9 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ ARM64

pywincode-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (210.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pywincode-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (195.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pywincode-0.1.0-cp312-cp312-win_amd64.whl (126.7 kB view details)

Uploaded CPython 3.12Windows x86-64

pywincode-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl (423.5 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

pywincode-0.1.0-cp312-cp312-musllinux_1_2_aarch64.whl (387.3 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ ARM64

pywincode-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (210.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pywincode-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (196.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pywincode-0.1.0-cp311-cp311-win_amd64.whl (126.9 kB view details)

Uploaded CPython 3.11Windows x86-64

pywincode-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl (424.6 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

pywincode-0.1.0-cp311-cp311-musllinux_1_2_aarch64.whl (388.5 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ ARM64

pywincode-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (211.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pywincode-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (197.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pywincode-0.1.0-cp310-cp310-win_amd64.whl (127.0 kB view details)

Uploaded CPython 3.10Windows x86-64

pywincode-0.1.0-cp310-cp310-musllinux_1_2_x86_64.whl (424.7 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

pywincode-0.1.0-cp310-cp310-musllinux_1_2_aarch64.whl (388.6 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ ARM64

pywincode-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (212.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pywincode-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (197.3 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for pywincode-0.1.0.tar.gz
Algorithm Hash digest
SHA256 237ac27b03fb7c1983c52c2b0eb5e5145ac0b40eea83bb1d1ee0ddf609fcdff6
MD5 9059af45aa5d5595d1ccf7d8031bef48
BLAKE2b-256 cf534c4a1f48131af5d57ef441fcad09ec37d556b0b437df7c37cb93d21e229d

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pywincode-0.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 126.2 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pywincode-0.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 aed23dbd9bba1f298dffc17a29e4ce803250937624899c0ea13d7ff1aed3e27c
MD5 9f9ee98ce576741dd04f55df59717946
BLAKE2b-256 c2a45dbff0b8bc5177e18f675d88040d86018aa813e1c5ace214bb0ec736a9c4

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f6ef23b2a4d49a3a76525bf58797d92b4698f4ef6ec88c0b8ebbeca8fe26ca66
MD5 1729449c74543aa0fe92da0d1d603def
BLAKE2b-256 25b6bfed7f1d0e41af64509b51198b04819005790c13ef956540c8914009763b

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp313-cp313-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp313-cp313-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f2d7e0f598b53cc80e7b4ce3a37c2b3d11576b1220672d96db41b732493ddc56
MD5 48039d9e4bd3dd79c00277a4be645855
BLAKE2b-256 20177902faed7b8e645cb9d1a11990eccb0528ff300698058fae38eae4d68bfc

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9843537d9a0b9ffc59ab1523fdc43143747e2b924893c72720043976eb282b50
MD5 4cbdc8a52cd36e292c3d9ff4439c671f
BLAKE2b-256 26b1ff8dd83d07bf45c17117ffef55bff6c41ad102d20e539e8a04743d9e2d20

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8a37c3a476d0256b1f90dbca829fb61e53c518b4abba67aafe435e36836333f6
MD5 addb1911963dcece1e164b2bb823700c
BLAKE2b-256 5cbeb94c05f6be3748802464440864c998659a56daa5822ccd9eb545567010c4

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pywincode-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 126.7 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pywincode-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a16420b5abecfd2d5b0c6d8a45a4d9d932cecd9e1177f2b202009bbd639193db
MD5 569302e86676fd4cfb188aa255cf3c72
BLAKE2b-256 f1d9ca09b14016384738ff6ecb11fd8144d59cbef8f4c4808d791b4a0ad55768

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b0dcdd59b040c2ced30252a63066bcb9335750fe07e169af863f3355cb6098de
MD5 bec7df8dbf51e509668a70d60548ad8e
BLAKE2b-256 eaae6d31b7b8b1c7aaadfbdc3e428fa40eae3e82e9b96c6747742dcf50a82f66

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp312-cp312-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp312-cp312-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 bd92c87cc2c4649ebe3de8c5cc56a5c780af3d22527e4ed5591667be966c9842
MD5 84534a3863376165db01d3258eadd55b
BLAKE2b-256 bc77fbe3eb78a1649171170dbb4c9d62014e011beaad98587aae718459086b0d

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 816c93962aa3dfe591909e7e7fb35e4a4b219951ba95109f2e7ff9696d8cbc69
MD5 11a401d0ea7ef32a288211c6e722d143
BLAKE2b-256 11fa86bfffefde0945a5f6251528204b042226672cd8534f566b76b79b2bfa95

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b42912bc18a5c2f6f100a1898520fc999c2823bafe3d07a32173b30cc2ad87f8
MD5 1da3d4135f72b35ab5b8af336836354b
BLAKE2b-256 9141d505a04ab1fbe4f5266c4b4ec63d87d5988cfa02cce490deacb732e22d0b

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: pywincode-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 126.9 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pywincode-0.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c5f5b6dbe975651318b02b0191b31792d82dc098ddb8060b5875227dc3e07975
MD5 42f9de7d323f345101d5eb5600a8f9f8
BLAKE2b-256 c6c21b79d20e4b70fc9467b7a826b2f10403dcabc8a64ca7c4e8e30f58324d07

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1c65ebc44644a88266d19ead785f0cfd87e190128c0e07b86572e35d42a714f2
MD5 1b6ece4f086e639ce2a4ff236d920bad
BLAKE2b-256 bbb8226a13d57574bced8ec247e0767a06f6ec0e714467d03608100c805b4b6b

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp311-cp311-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp311-cp311-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 4ea6c53e59fa18858af00654bb85ecccdd2952b15e95d4aaed8f2bbaa233cc7a
MD5 f0d752afa1d9247192fd034a474700ee
BLAKE2b-256 03151ed4d83a6db42c3123688b1ba45a85631976c8ec0472dfa717e73b19bd26

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fbf8f477167f771a0ff12499dcaa7b9e4cefe8147248b0fd86debbdb636dab95
MD5 798abe05ee1014861057ba2bff4c7c43
BLAKE2b-256 836942828e0ec0235d365dda19b185f3881a3b8c51785b6a32c478ec951979a7

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ba7917ce74c654ca7b6cb3ac57c7719fb13250ce9c297fd2bd1fd7dd35b70cb3
MD5 3a60c03a120d191ae2798312811910d1
BLAKE2b-256 20714f9c852b1add32c017242242b2297ea9ce79b0ef1e28524f7ece38e6ef1a

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: pywincode-0.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 127.0 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pywincode-0.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 648d5233173562c63e6b9466d01682394900e76bc92f381f252905bf8b10fccf
MD5 9557b6ad8d1707aa8562eeaec3189b71
BLAKE2b-256 c60445948f5aa20e1e42e5888135383f7b41480bc8af745116b89f015334f69a

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5c075f7ac88da9f1280b0752a23ceb087b26c8fe7daff5bf7d1f902cf4b6d9a0
MD5 41aa21eb8eab72ee0b8af6d13cc039d4
BLAKE2b-256 e7fac9a4c0950b5af07b879b53d5afe4492686f20992e1fe85d073410ea39d12

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp310-cp310-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp310-cp310-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 cc9159bdef1a2ca3819f6ae58f1e066f1ff141612c245297be31654ba6b04759
MD5 8aa26145aca75816a999fa8e83bfb27e
BLAKE2b-256 074b0fc1e6362eacf2128cbab3971f99eb3faa552922e8444f15becafca1e611

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bba7241da922621451871ca74e907cb9323639019e9fe4f9e1fdaca146f97bea
MD5 389ff2cd91d60a53cb3bd92d5ec9f859
BLAKE2b-256 3555b92cbcee874189309adda39b8e5b38c043125518eb1fb8901b2bcad29007

See more details on using hashes here.

File details

Details for the file pywincode-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pywincode-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 270ef79c658e9599510645dd1164471aa6070844bf066c522b3cf7e9836e0d55
MD5 b58c60c03b7c495070235d2317a5e06b
BLAKE2b-256 cc6f135afb2fbb105e32073ad41e81e2dfd97e9fe4200fb1c80d2c40f16e5b57

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