Tycho Python
A python implementation of the tycho binary format.
Features
- Full Implementation
- Serialise/Deserialise python objects into binary format.
- Uses Builtin errors/types.
- No dependencies
Installation
You can install using pip:
pip install tycho-py
or add the following to your requirements file:
tycho-py==0.1.5
Once installed, import the library:
import tycho
Documentation
Basic usage
The following example takes a python object and encodes it into tycho bytes.
import tycho
data = {"foo": "Hello World", "bar": 10, "baz": True}
tycho.to_bytes(data).hex(" ")
# 40 03 03 66 6f 6f 1e 0b 48 65 6c 6c 6f 20 57 6f 72 6c 64 03 62 61 72 11 0a 03 62 61 7a 10 01
The following example takes a tycho bytes and decodes it into bytes.
import tycho
data = bytes.fromhex("40 03 03 66 6f 6f 1e 0b 48 65 6c 6c 6f 20 57 6f 72 6c 64 03 62 61 72 11 0a 03 62 61 7a 10 01")
print(tycho.from_bytes(data))
# {'foo': 'Hello World', 'bar': 10, 'baz': True}
Advanced usage
As python does not map to the rust/serde data model, types have to be inferred. When encoding from a python object into bytes two processes take place, Serialisation and Encoding. See this diagram below.
Python Object
\/ /\ Serialise
Tycho Classes
\/ /\ Encoding
Bytes
Serialisation is expensive, as types have to matched and inferred.
To allow better quicker encoding, the Tycho Classes are exposed to the user.
These reproduce the same result as above examples.
import tycho
data = tycho.Structure({
"foo": tycho.String("Hello World"),
"bar": tycho.Unsigned8(10),
"baz": tycho.Boolean(False)
})
print(tycho.encode(data))
# 40 03 03 66 6f 6f 1e 0b 48 65 6c 6c 6f 20 57 6f 72 6c 64 03 62 61 72 11 0a 03 62 61 7a 10 01
import tycho
data = bytes.fromhex("40 03 03 66 6f 6f 1e 0b 48 65 6c 6c 6f 20 57 6f 72 6c 64 03 62 61 72 11 0a 03 62 61 7a 10 01")
print(tycho.decode(data))
# Structure({'foo': String('Hello World'), 'bar': Unsigned8(10), 'baz': Boolean(True)})
Using the Tycho Classes also allow for usage of the Variant Object. As python does not have rust-like enums,
there is no serialisation/deserialisation implemented for them.
Within the library these Tycho Classes are named Elements to keep parity between the rust library and others.
Methods
-
tycho.encode(element) -> bytes- Encode an Element object into bytes
-
tycho.decode(bytes) -> Element- Decode bytes into an Element
-
tycho.serialise(object) -> Element- Serialise a python object into an element
-
tycho.deserialise(element) -> object- Deserialise a element into a python object
-
tycho.from_bytes(object) -> Element- Serialise and encode a python object into bytes.
-
tycho.deserialise(element) -> object- Decode and Deserialise bytes into a python object.
Classes
Base classes
tycho.Elementtycho.Valuetycho.NumericalValue
Type classes
tycho.Unittycho.Optiontycho.Structuretycho.Arraytycho.Varianttycho.Listtycho.Maptycho.Booleantycho.Unsigned8tycho.Unsigned16tycho.Unsigned32tycho.Unsigned64tycho.Unsigned128tycho.Signed8tycho.Signed16tycho.Signed32tycho.Signed64tycho.Signed128tycho.Float32tycho.Float64tycho.Chartycho.Stringtycho.Bytes
Warning
Within the spec it is possible for a
Mapto containfloat32andfloat64, However some libraries map not accept such values (due to their unhashability)
Metadata
Release files for tycho-py 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| tycho-py-0.1.5.tar.gz | 8.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tycho_py-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.5 kB
Release files / tycho-py-0.1.5.tar.gz
| Download URL | tycho-py-0.1.5.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c1d4125b20a38a5ef0f7e157819018a79554bea0da10f8916c49928aeda12b38
|
|
BLAKE2b-256 checksum How to use checksums |
68e59f24ec062873849e51fe2a986740dbf4bc208375fc3fcda861ddb30a0c10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9
|
Release files / tycho_py-0.1.5-py3-none-any.whl
| Download URL | tycho_py-0.1.5-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c34bb819bad7c7145839e229719d54ed64ae3782560737d8a543ad587840d7f1
|
|
BLAKE2b-256 checksum How to use checksums |
ecbcf1df89c6682b752c26c916b74ff628c14c207c1e4a842894892e61c20eb1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.9
|
Security for tycho-py 0.1.5
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.