BIPF-Python
A Python library for BIPF (Binary In-Place Format)
See https://github.com/ssbc/bipf for the origin of BIPF and a description of the format. A condensed writeup is at the end of this document.
Quick start (the interface is the same as in json and cbor2):
- install the library:
python3 -m pip install bipf - in your code:
from bipf import dumps, loads dumps(<your_python_data>)serializes the object to bytesloads(<some_bipf_bytes>)restores a BIPF-serialized object
A rich demo in tests/demo.py also generates a testvector. The output is:
# encoded 80 bytes: f50418666f6f8c02127fff0a800a810aff0a000a010a7f12800012007f1a0080000e002179656168061862616695014046726564686f6c6d4305413da6832fbc3f186261722868656c6c6f1862617a06
# generator demo:
> 18666f6f 8c02127fff0a800a810aff0a000a010a7f12800012007f1a0080000e00217965616806
> 0 127fff
> 1 0a80
> 2 0a81
> 3 0aff
> 4 0a00
> 5 0a01
> 6 0a7f
> 7 128000
> 8 12007f
> 9 1a008000
> 10 0e00
> 11 2179656168
> 12 06
> 18626166 95014046726564686f6c6d4305413da6832fbc3f
> 4046726564686f6c6d 4305413da6832fbc3f
> 18626172 2868656c6c6f
> 1862617a 06
# parse entire object and read a single value
{'foo': [-129, -128, -127, -1, 0, 1, 127, 128, 32512, 32768, False, b'yeah', None], 'baf': {'Fredholm': 0.1101000100000001}, 'bar': 'hello', 'baz': None}
hello
# seek and decode a single value
key pos 69 --> hello
path pos 56 --> 0.1101000100000001
# keys can be bytes, int, double, bool and None:
# input:
{b'\x00\x01': 'ah', 99: 'eh', 4.3: 'ih', True: 'oh', None: 'uh'}
# encoded 34 bytes: 85021100011061680a631065684333333333333311401069680e01106f6806107568
# parse entire serialization
{b'\x00\x01': 'ah', 99: 'eh', 4.3: 'ih', True: 'oh', None: 'uh'}
BIPF format
BIPF uses type-length-value (TLV) encoding for atomic types as well as for lists and dictionaries. This allows to skip entries without having to hunt for an end-of-list or end-of-dict marker.
TLV:= concatenation oftag_bytesandvalue_bytestag_bytes:= varint_encoding( len(value_bytes) << 3 |type_bits)type_bits:=
value bytes:
TYPE_STRING # 000 utf-8 encoded string
TYPE_BYTES # 001 raw
TYPE_INT # 010 signed little endian, 1 to 8 bytes, minimal size
TYPE_DOUBLE # 011 64bit IEEE-754 float, little endian
TYPE_LIST # 100 sequence of BIPF-encoded elements
TYPE_DICT # 101 sequence with alternating BIPF-encoded key and val
TYPE_BOOLNONE # 110 length==0 -> None, else one byte with 0 or 1 for F/T
TYPE_RESERVED # 111
- varint_encoding is
unsigned LEB128as used in WebAssembly - keys for dictionaries can have any type except list or dict (and reserved)
Metadata
Release files for bipf 0.0.8
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 | Actions |
|---|---|---|---|---|
| bipf-0.0.8.tar.gz | 6.3 kB | Without provenance | Details for bipf-0.0.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bipf-0.0.8-py3-none-any.whl | Python 3 | none | any | Details for bipf-0.0.8-py3-none-any.whl |
Total release size: 12.9 kB
Release files / bipf-0.0.8.tar.gz
| Download URL | bipf-0.0.8.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35b25d85a8a7a10b55e7c16a40677646f0120e52610b746b7c70d906a89a42de
|
|
BLAKE2b-256 checksum How to use checksums |
67044ecc765eb0eee0f9a1208a58636c2439d61476632f4115604e0bd127a282
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.10
|
Release files / bipf-0.0.8-py3-none-any.whl
| Download URL | bipf-0.0.8-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3306e27b5d7c78e373d5272dacc05b7150545ae1063b525550cba53e12cf958b
|
|
BLAKE2b-256 checksum How to use checksums |
caac0da8cc5b3c1c012b9fc712a881675e21b1f07db6bed8c81c77cf9d3cd0ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.10
|
Security for bipf 0.0.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.
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.