Skip to main content

StructOvO

GitHub License GitHub Repo stars PyPi Downloads Python

A Python library offering a more concise syntax for data packing.

Installation

  • From pypi
pip install structovo

Usage

from structovo import *


class PackA(Packet):
    a: PADDING
    b: BYTE = b'A'
    c: CHAR = -1
    d: UCHAR = 1
    e: BOOL = False
    f: SHORT = -2
    g: USHORT = 2
    h: INT = -3
    i: UINT = 3
    j: LONG = -4
    k: ULONG = 4
    l: LONGLONG = -5
    m: ULONGLONG = 5
    n: SIZET = 12
    o: SSIZET = 34
    p: BINARY16 = 3.14
    q: FLOAT = 3.14
    r: DOUBLE = 3.14
    s: FixedString = (b"hello", 10)
    t: LengthPrefixedString = b"world"
    u: UnsignedPointer = 0x0d000721
    v: bytes = b'raw_bytes'


r = PackA.build(endianness=Endianness.NATIVE)
hex_list = [format(byte, '02x') for byte in r]
hex_str = ' '.join(hex_list)
print(hex_str)

And you will get:

00 41 ff 01 00 fe ff 02 00 fd ff ff ff 03 00 00 00 fc ff ff ff 04 00 00 00 fb ff ff ff ff ff ff ff 05 00 00 00 00 00 00 00 0c 00 00 00 00 00 00 00 22 00 00 00 00 00 00 00 48 42 c3 f5 48 40 1f 85 eb 51 b8 1e 09 40 68 65 6c 6c 6f 00 00 00 00 00 05 77 6f 72 6c 64 21 07 00 0d 00 00 00 00 72 61 77 5f 62 79 74 65 73

Advance

Supported Endianness

  • Endianness.BIG: Big-endian
  • Endianness.LITTLE: Little-endian
  • Endianness.NETWORK: Big-endian
  • Endianness.NATIVE: Depend on your device (Default)

Custom Data Types

You can define your own data types by simply inheriting the BaseType class:

from typing import Tuple, Type
from structovo import BaseType, Endianness


class MyDataType(BaseType):
    def check_validation(self) -> Tuple[bool, Type]:
        # Implement the validation of whether the self.value is valid.
        return ...

    def encode(self, endianness: Endianness) -> bytes:
        # Implement the operation of converting self.value to bytes.
        return ...    

Like this:

from typing import Tuple, Type
from structovo import BaseType, Endianness


class BYTE(BaseType):
    def check_validation(self) -> Tuple[bool, Type]:
        result = isinstance(self.value, bytes)
        return result, bytes

    def encode(self, endianness: Endianness) -> bytes:
        return self._pack('c', endianness)

Release files for structovo 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 structovo 1.0.1
File Size Uploaded
structovo-1.0.1.tar.gz 3.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for structovo 1.0.1
File Interpreter ABI Platform
structovo-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size:8.8 kB

Release files / structovo-1.0.1.tar.gz

Download URL structovo-1.0.1.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9d4c53dbf81df7b8af9d65c628ba4577feedc377dd42c8292fa67f8daad59031
BLAKE2b-256 checksum
How to use checksums
212f8461762a146a625483add82bc24e3e9d466ff7907e569b70690f3ffcaa93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 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 Feb 7, 2025.

Transparency log

Release files / structovo-1.0.1-py3-none-any.whl

Download URL structovo-1.0.1-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5436ea2bdd357631e2e387ee3053dab555e62b97a46dce0c0805ac3e713f43fd
BLAKE2b-256 checksum
How to use checksums
a31f5d95be8f2945b7caf938bb93b06feacdf5a315a33d7fdaacb4cfde42d315
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 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 Feb 7, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.0

2 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