sbe-python
Easy to use, fast, pure Python FIX SBE encoder and decoder.
Install
pip install sbe
Usage
Simple Decoding
Decode SBE to Python dictionaries in one line. Good for exploratory data analysis.
import sbe
with open('your-schema.xml', 'r') as f:
schema = sbe.Schema.parse(f)
wtih open('your-data.sbe', 'rb') as f:
buf = f.read()
# Get a Python dict in one-line
x = schema.decode(buf)
x.name # The template message name
x.value
# {'userId': 11,
# 'timestamp': 1598784004840,
# 'orderSize': 0,
# 'price': 5678.0,
# ...
# If you need an initial offset, apply it Pythonically
schema.decode(buf[19:])
# decode_header to filter out messages based on header to avoid decoding
# message bodies that are not needed
schema.decode_header(buf)['templateId']
High Performance Decoding (Wrapping)
This gives you decent performance while still retaining high code readability.
import sbe
with open('your-schema.xml', 'r') as f:
schema = sbe.Schema.parse(f)
wtih open('your-data.sbe', 'rb') as f:
buf = f.read()
# Wrap the buffer without decoding it, fields are converted to Python variables
# on demand
x = schema.wrap(buf)
x.header['templateId']
x.body['price']
x.body['someGroup'][2]['price']
Direct Access with Pointers
get_raw_pointer gives you the required information to unpack a variable from memoryview / bytes. This gets you very close to the fastest achievable performance in Python:
import sbe
with open('your-schema.xml', 'r') as f:
schema = sbe.Schema.parse(f)
header_pointer = schema.header_wrapper.get_raw_pointer('templateId')
# Let's say we are only interested in messages of templateId == 3
price_pointer = schema.message_wrappers[3].get_raw_pointer('price')
wtih open('your-data.sbe', 'rb') as f:
buf = f.read()
# pass `memoryview` to `unpack` to avoid copying
buf = memoryview(buf)[initial_offset:]
template_id = header_pointer.unpack(buf) # calls buf[offset:offset+size].cast("I")[0] directly
if template_id == 3:
print(price_pointer.unpack(buf))
Encoding
import sbe
with open('./your-schema.xml', 'r') as f:
schema = sbe.Schema.parse(f)
# message_id from the schema you want to encode
message_id = 3
obj = {
'userId': 11,
'price': 5678.0,
# ...
}
# Encode from Python dict in one-line
schema.encode(schema.messages[3], obj)
# You can supply your header values as a dict
schema.encode(schema.messages[3], obj, headers)
Metadata
Release files for sbe 0.4.3
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 |
|---|---|---|---|---|
| sbe-0.4.3.tar.gz | 12.3 kB | Without provenance | Details for sbe-0.4.3.tar.gz |
Release files / sbe-0.4.3.tar.gz
| Download URL | sbe-0.4.3.tar.gz |
|---|---|
| Size | 12.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8913b543302e89353f1fb90556606883e795b5c6367b2c27fb039450c0118f7a
|
|
BLAKE2b-256 checksum How to use checksums |
37f48fb98b65eb24d4a02b21fc06895bf6586b042dcc590e2b556efdd6e062db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.5
|
Security for sbe 0.4.3
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.