Skip to main content

A project to allow serialising and deserialising python objects

Project description

serialise

this is a simple library to serialise and deserialise python objects. it can serialise any object given it has a serialiser written for it. Many python builtins already have serialisers

to create a serialiser you use the Serialiser class

here is an example (the default list serialiser but more friendly)

from serialiser import Serialiser, read_size, write_size, serialise, deserialise
from io import BytesIO
def list_serialiser(data: list)->bytes:
	# create a bytearray this is a more convient way of creating bytes
	rv = bytearray()
	# add the length of the list
	# write size writes an int
	rv.extend(write_size(len(data)))
	# for each element in the list add the serialised element
	for el in data: rv.extend(serialise(el))
	return bytes(rv)
def list_deserialiser(data: bytes)->list:
	# the serialiser in reverse
	# create a BytesIO which is a more convient way of reading bytes
	data = BytesIO(data)
	# first read the length
	length = read_size(data, "list length")
	# then deserialise length elements from the data and reutrn them in an array
	return [deserialise(data) for _ in range(length)]
# register the Serialiser by createing a new instance of the Serialiser class
Serialiser(
	list,
	list_serialiser,
	list_deserialiser
)

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

serialise-0.0.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

serialise-0.0.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file serialise-0.0.0.tar.gz.

File metadata

  • Download URL: serialise-0.0.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for serialise-0.0.0.tar.gz
Algorithm Hash digest
SHA256 5bf89866ccff50cf42cda08d21959d8ac4f8aaf8c24c113060a53588fb0ebbdd
MD5 8222507b8f35de94c71c3cab3c8fbefd
BLAKE2b-256 6fadb59b3f7fb711274c4c4195fd9070ab0923231b2fdaea1ae0870d1566e11e

See more details on using hashes here.

File details

Details for the file serialise-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: serialise-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for serialise-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 45c06bb3d0b875af88b3a93dac70a8a066127318efd740ac926c28e14cd7fbe6
MD5 6e9af48bcb8442fe95d6fd91186c9740
BLAKE2b-256 e4341c52245d3b54956e196e857c9930577bb6f567b3a5e1835e41a26ca66781

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