Skip to main content

No project description provided

Project description

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 avoid 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

# 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)

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

sbe-0.2.8.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

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

sbe-0.2.8-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file sbe-0.2.8.tar.gz.

File metadata

  • Download URL: sbe-0.2.8.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.26.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5

File hashes

Hashes for sbe-0.2.8.tar.gz
Algorithm Hash digest
SHA256 956ae12e9f6b1c2a8f732e1a6e0916a1d92e99275d8b0b87778bc700325b070f
MD5 c96acca18fe70e6e1903b878f074bef7
BLAKE2b-256 67d7b2d5c7c0e47189b00c49ccdd5708c0d53334af59e665b4eddd0e3252ec44

See more details on using hashes here.

File details

Details for the file sbe-0.2.8-py3-none-any.whl.

File metadata

  • Download URL: sbe-0.2.8-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.26.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5

File hashes

Hashes for sbe-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 31d4b6a63fc434276510bd74f5f3b41fec8851820c2ec0d0b6cf2fc673d627ce
MD5 920bedc391954c6d70cb7fc4c730d5a8
BLAKE2b-256 179aebf56b7402e11eed6bae50dcdaed1af0d82e845ca33c426f2236d0dbde90

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