py-ssz
Python implementation of the Simple Serialization encoding and decoding
Contents
ssz package
Subpackages
ssz.cache package
Submodules
ssz.cache.cache module
ssz.cache.utils module
Module contents
ssz.sedes package
Submodules
ssz.sedes.base module
- class ssz.sedes.base.BaseBitfieldCompositeSedes(*args, **kwds)
Bases:
BaseSedes
[TSerializable
,TDeserialized
]
- class ssz.sedes.base.BaseProperCompositeSedes(*args, **kwds)
Bases:
BaseSedes
[TSerializable
,TDeserialized
]
ssz.sedes.basic module
- class ssz.sedes.basic.BasicSedes(size: int)
Bases:
BaseSedes
[TSerializable
,TDeserialized
]- get_fixed_size()
- get_hash_tree_root(value: TSerializable) Hash32
- is_fixed_sized = True
- class ssz.sedes.basic.BitfieldCompositeSedes(*args, **kwds)
Bases:
BaseBitfieldCompositeSedes
[TSerializable
,TDeserialized
]
- class ssz.sedes.basic.HomogeneousProperCompositeSedes(*args, **kwds)
Bases:
ProperCompositeSedes
[TSerializable
,TDeserialized
]
- class ssz.sedes.basic.ProperCompositeSedes(*args, **kwds)
Bases:
BaseProperCompositeSedes
[TSerializable
,TDeserialized
]
ssz.sedes.bitlist module
ssz.sedes.bitvector module
ssz.sedes.boolean module
ssz.sedes.byte module
ssz.sedes.byte_list module
- class ssz.sedes.byte_list.ByteList(max_length: int)
Bases:
List
[Union
[bytes
,bytearray
],bytes
]Equivalent to List(byte, size) but more convenient & efficient.
When encoding a series of bytes, List(byte, …) requires an awkward input shaped like:
(b'A', b'B', b'C')
. ByteList accepts a simplebytes
object likeb'ABC'
for encoding.
ssz.sedes.byte_vector module
ssz.sedes.container module
- class ssz.sedes.container.Container(field_sedes: Sequence[BaseSedes[Any, Any]])
Bases:
ProperCompositeSedes
[Sequence
[Any
],Tuple
[Any
, …]]- deserialize_fixed_size_parts(stream: IO[bytes]) Iterable[Tuple[Tuple[Any], Tuple[int, BaseSedes[Any, Any]]]]
- deserialize_variable_size_parts(offset_pairs: Tuple[Tuple[int, BaseSedes[Any, Any]], ...], stream: IO[bytes]) Iterable[Any]
- get_fixed_size()
- property is_fixed_sized
ssz.sedes.list module
ssz.sedes.serializable module
- class ssz.sedes.serializable.BaseSerializable(*args, cache=None, **kwargs)
Bases:
Sequence
- as_dict()
- cache = None
- copy(*args, **kwargs)
- property hash_tree_root
- reset_cache()
- class ssz.sedes.serializable.Meta(has_fields, fields, container_sedes, field_names, field_attrs)
Bases:
tuple
- class ssz.sedes.serializable.MetaSerializable(name, bases, namespace)
Bases:
ABCMeta
- get_fixed_size()
- property is_fixed_sized
- class ssz.sedes.serializable.Serializable(*args, cache=None, **kwargs)
Bases:
BaseSerializable
The base class for serializable objects.
- ssz.sedes.serializable.make_immutable(value)
- ssz.sedes.serializable.merge_args_to_kwargs(args, kwargs, arg_names)
- ssz.sedes.serializable.merge_kwargs_to_args(args, kwargs, arg_names)
- ssz.sedes.serializable.validate_args_and_kwargs(args, kwargs, arg_names)
ssz.sedes.signed_serializable module
- class ssz.sedes.signed_serializable.MetaSignedSerializable(name, bases, namespace)
Bases:
MetaSerializable
- class ssz.sedes.signed_serializable.SignedMeta(has_fields, fields, container_sedes, signed_container_sedes, field_names, field_attrs)
Bases:
tuple
- class ssz.sedes.signed_serializable.SignedSerializable(*args, cache=None, **kwargs)
Bases:
BaseSerializable
- property signing_root
ssz.sedes.uint module
ssz.sedes.vector module
Module contents
- ssz.sedes.infer_sedes(value)
Try to find a sedes objects suitable for a given Python object.
ssz.tools package
Submodules
ssz.tools.codec module
ssz.tools.dump module
- ssz.tools.dump.dump(value, sedes=None, codec=<class 'ssz.tools.codec.DefaultCodec'>)
- ssz.tools.dump.dump_bits(value, sedes, codec)
- ssz.tools.dump.dump_boolean(value, sedes, codec)
- ssz.tools.dump.dump_bytes(value, sedes, codec)
- ssz.tools.dump.dump_container(value, sedes, codec)
- ssz.tools.dump.dump_hashable_container(value, codec)
- ssz.tools.dump.dump_hashable_sequence(value, codec)
- ssz.tools.dump.dump_integer(value, sedes, codec)
- ssz.tools.dump.dump_list(value, sedes, codec)
- ssz.tools.dump.dump_serializable(value, codec)
- ssz.tools.dump.dump_vector(value, sedes, codec)
- ssz.tools.dump.to_formatted_dict(value, sedes=None, codec=<class 'ssz.tools.codec.DefaultCodec'>)
ssz.tools.parse module
- ssz.tools.parse.from_formatted_dict(value, sedes, codec=<class 'ssz.tools.codec.DefaultCodec'>)
- ssz.tools.parse.parse(value, sedes, codec=<class 'ssz.tools.codec.DefaultCodec'>)
- ssz.tools.parse.parse_bits(value, sedes, codec)
- ssz.tools.parse.parse_boolean(value, sedes, codec)
- ssz.tools.parse.parse_bytes(value, sedes, codec)
- ssz.tools.parse.parse_container(value, sedes, codec)
- ssz.tools.parse.parse_hashable(value, hashable_cls, codec)
- ssz.tools.parse.parse_integer(value, sedes, codec)
- ssz.tools.parse.parse_list(value, sedes, codec)
- ssz.tools.parse.parse_serializable(value, serializable_cls, codec)
- ssz.tools.parse.parse_vector(value, sedes, codec)
Module contents
Submodules
ssz.abc module
- class ssz.abc.HashableStructureAPI(*args, **kwds)
-
- abstract property chunks: PVector[Hash32]
- abstract property elements: PVector[TElement]
- abstract evolver() HashableStructureEvolverAPI[TStructure, TElement]
- abstract classmethod from_iterable_and_sedes(iterable: Iterable[TElement], sedes: BaseProperCompositeSedes, max_length: int | None)
- abstract property hash_tree_root: Hash32
- abstract property raw_root: Hash32
- abstract transform(*transformations)
- class ssz.abc.HashableStructureEvolverAPI(hashable_structure: TStructure)
Bases:
ABC
,Generic
[TStructure
,TElement
]- abstract persistent() TStructure
- class ssz.abc.ResizableHashableStructureAPI(*args, **kwds)
Bases:
HashableStructureAPI
[TElement
]- abstract append(value: TElement) TStructure
- abstract evolver() ResizableHashableStructureEvolverAPI[TStructure, TElement]
ssz.codec module
- ssz.codec.decode(ssz, sedes)
Decode a SSZ encoded object.
- ssz.codec.encode(value, sedes=None)
Encode object in SSZ format. sedes needs to be explicitly mentioned for encode/decode of integers(as of now). sedes parameter could be given as a string or as the actual sedes object itself.
ssz.constants module
ssz.exceptions module
- exception ssz.exceptions.DeserializationError
Bases:
SSZException
Exception raised if deserialization fails.
- exception ssz.exceptions.SSZException
Bases:
Exception
Base class for exceptions raised by this package.
- exception ssz.exceptions.SerializationError
Bases:
SSZException
Exception raised if serialization fails.
ssz.hash module
ssz.hash_tree module
- class ssz.hash_tree.HashTree(raw_hash_tree: PVector[PVector[Hash32]], chunk_count: int | None = None)
Bases:
PVector
[Hash32
]- property chunks: PVector[Hash32]
- count(value) integer -- return number of occurrences of value
- evolver()
- index(value[, start[, stop]]) integer -- return first index of value.
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- property root: Hash32
- transform(*transformations)
- class ssz.hash_tree.HashTreeEvolver(hash_tree: HashTree)
Bases:
object
- delete(index, stop=None)
- remove(value)
- ssz.hash_tree.append_chunk_to_tree(hash_tree: PVector[PVector[Hash32]], chunk: Hash32) PVector[PVector[Hash32]]
- ssz.hash_tree.compute_hash_tree(chunks: Iterable[Hash32], chunk_count: int | None = None) PVector[PVector[Hash32]]
- ssz.hash_tree.generate_chunk_tree_padding(unpadded_chunk_tree: PVector[Hash32], chunk_count: int | None) Generator[Hash32, None, None]
- ssz.hash_tree.generate_hash_tree_layers(chunks: PVector[Hash32]) Generator[PVector[Hash32], None, None]
- ssz.hash_tree.pad_hash_tree(unpadded_chunk_tree: PVector[PVector[Hash32]], chunk_count: int | None = None) PVector[PVector[Hash32]]
- ssz.hash_tree.recompute_hash_in_tree(hash_tree: PVector[PVector[Hash32]], layer_index: int, hash_index: int) PVector[PVector[Hash32]]
ssz.hashable_container module
- class ssz.hashable_container.FieldDescriptor(name: str)
Bases:
object
Descriptor translating from __getattr__ to __getitem__ calls for a given attribute.
- ssz.hashable_container.GenericMetaHashableContainer
alias of
MetaHashableContainer
- ssz.hashable_container.GenericMetaSignedHashableContainer
alias of
MetaSignedHashableContainer
- class ssz.hashable_container.HashableContainer(*args, **kwargs)
Bases:
BaseHashableStructure
[TElement
]Base class for hashable containers.
- evolver() HashableContainerEvolver[TStructure, TElement]
- property hash_tree_root: Hash32
- class ssz.hashable_container.HashableContainerEvolver(hashable_structure: TStructure)
Bases:
HashableStructureEvolver
[TStructure
,TElement
]Base class for evolvers for hashable containers.
Subclasses (created dynamically by MetaHashableContainer when creating the corresponding HashableContainer) should add settable field descriptors for all fields.
- class ssz.hashable_container.Meta(fields, field_names, field_names_to_element_indices, container_sedes, evolver_class)
Bases:
tuple
- evolver_class: Type[HashableContainerEvolver]
Alias for field number 4
- class ssz.hashable_container.MetaHashableContainer(name: str, bases: Tuple[Type, ...], namespace: Dict[str, Any])
Bases:
ABCMeta
Metaclass which creates HashableContainers.
- deserialize(data)
- get_fixed_size()
- get_hash_tree_root(value)
- get_hash_tree_root_and_leaves(value, cache)
- get_key(value)
- get_sedes_id()
- property is_fixed_sized
- serialize(value)
- class ssz.hashable_container.MetaSignedHashableContainer(name, bases, namespace)
Bases:
MetaHashableContainer
- class ssz.hashable_container.SettableFieldDescriptor(name: str)
Bases:
FieldDescriptor
Settable variant of FieldDescriptor for evolver.
- class ssz.hashable_container.SignedHashableContainer(*args, **kwargs)
Bases:
HashableContainer
[TElement
]- property signing_root: Hash32
- ssz.hashable_container.get_field_sedes_from_fields(fields: Sequence[Tuple[str, BaseSedes]]) Generator[BaseSedes, None, None]
- ssz.hashable_container.get_meta_from_bases(bases: Tuple[Type, ...]) Meta | None
Return the meta object defined by one of the given base classes.
Returns None if no base defines a meta object. Raises a TypeError if more than one do.
ssz.hashable_list module
- class ssz.hashable_list.HashableList(elements: PVector[TElement], hash_tree: HashTree, sedes: BaseProperCompositeSedes, max_length: int | None = None)
Bases:
BaseResizableHashableStructure
[TElement
],Sequence
[TElement
]- property hash_tree_root: Hash32
ssz.hashable_structure module
- class ssz.hashable_structure.BaseHashableStructure(elements: PVector[TElement], hash_tree: HashTree, sedes: BaseProperCompositeSedes, max_length: int | None = None)
Bases:
HashableStructureAPI
[TElement
]- property chunks: PVector[Hash32]
- property elements: PVector[TElement]
- evolver() HashableStructureEvolverAPI[TStructure, TElement]
- classmethod from_iterable_and_sedes(iterable: Iterable[TElement], sedes: BaseProperCompositeSedes, max_length: int | None = None)
- property raw_root: Hash32
- property sedes: BaseProperCompositeSedes
- transform(*transformations)
- class ssz.hashable_structure.BaseResizableHashableStructure(elements: PVector[TElement], hash_tree: HashTree, sedes: BaseProperCompositeSedes, max_length: int | None = None)
Bases:
BaseHashableStructure
,ResizableHashableStructureAPI
[TElement
]- append(value: TElement) TResizableStructure
- evolver() ResizableHashableStructureEvolverAPI[TResizableStructure, TElement]
- class ssz.hashable_structure.HashableStructureEvolver(hashable_structure: TStructure)
Bases:
HashableStructureEvolverAPI
[TStructure
,TElement
]- persistent() TStructure
- class ssz.hashable_structure.ResizableHashableStructureEvolver(hashable_structure: TStructure)
Bases:
HashableStructureEvolver
,ResizableHashableStructureEvolverAPI
[TStructure
,TElement
]
- ssz.hashable_structure.get_appended_chunks(*, appended_elements: Sequence[bytes], element_size: int, num_padding_elements: int) Generator[Hash32, None, None]
Get the sequence of appended chunks.
- ssz.hashable_structure.get_num_padding_elements(*, num_original_elements: int, num_original_chunks: int, element_size: int) int
Compute the number of elements that would still fit in the empty space of the last chunk.
- ssz.hashable_structure.get_updated_chunks(*, updated_elements: Dict[int, bytes], appended_elements: Sequence[bytes], original_chunks: Sequence[Hash32], element_size: int, num_original_elements: int, num_padding_elements: int) Generator[Tuple[int, Hash32], None, None]
For an element changeset, compute the updates that have to be applied to the existing chunks.
The changeset is given as a dictionary of element indices to updated elements and a sequence of appended elements. Note that appended elements that do not affect existing chunks are ignored.
The pre-existing state is given by the sequence of original chunks and the number of elements represented by these chunks.
The return value is a dictionary mapping chunk indices to chunks.
- ssz.hashable_structure.update_element_in_chunk(original_chunk: Hash32, index: int, element: bytes) Hash32
Replace part of a chunk with a given element.
The chunk is interpreted as a concatenated sequence of equally sized elements. This function replaces the element given by its index in the chunk with the given data.
If the length of the element is zero or not a divisor of the chunk size, a ValueError is raised. If the index is out of range, an IndexError is raised.
>>> from ssz.hashable_structure import update_element_in_chunk >>> update_element_in_chunk(b"aabbcc", 1, b"xx") b'aaxxcc'
- ssz.hashable_structure.update_elements_in_chunk(original_chunk: Hash32, updated_elements: Dict[int, bytes]) Hash32
Update multiple elements in a chunk.
The set of updates is given by a dictionary mapping indices to elements. The items of the dictionary will be passed one by one to update_element_in_chunk.
ssz.hashable_vector module
- class ssz.hashable_vector.HashableVector(elements: PVector[TElement], hash_tree: HashTree, sedes: BaseProperCompositeSedes, max_length: int | None = None)
Bases:
BaseHashableStructure
[TElement
],Sequence
[TElement
]- property hash_tree_root: Hash32
ssz.tree_hash module
ssz.typing module
ssz.utils module
- ssz.utils.get_duplicates(values)
- ssz.utils.get_serialized_bytearray(value: Sequence[bool], bit_count: int, extra_byte: bool) bytearray
Module contents
Release Notes
py-ssz v0.4.0 (2023-12-07)
Breaking Changes
Drop support for python 3.7 (#134)
Internal Changes - for py-ssz Contributors
py-ssz v0.3.1 (2023-06-08)
Internal Changes - for py-ssz Contributors
py-ssz v0.3.0 (2022-08-19)
Breaking changes
Dropping official support for Python 3.6 (although it still worked as of the last test run). (#125)
Features
Bugfixes
Improved Documentation
Sort release notes with most recent on top (#124)
Internal Changes - for py-ssz Contributors
Upgrade black to a stable version, and pass newest style checks (#120)
Use the latest project template, which gives many developer-focused benefits: in making release notes, releasing new versions, etc. (#121)
Miscellaneous changes (#124):
Run black autoformat, as part of
make lint-roll
Added some tests to check length validation of
ByteList
andByteVector
When generating website docs from docstrings, skip tests
v0.2.4
Released 2020-03-24
Update pyrsistent dependency.
v0.1.0-alpha.8
Released 2018-05-05
Less strict class relationship requirement for equality of serializables - #71
v0.1.0-alpha.7
Released 2018-05-02
v0.1.0-alpha.6
Released 2018-04-23
No changes
v0.1.0-alpha.5
Released 2018-04-23
v0.1.0-alpha.4
Released 2018-04-09
Fix bug in serializable class - #56
v0.1.0-alpha.3
Released 2018-04-04
Implement spec version 0.5.0
v0.1.0-alpha.2
Released 2018-02-05
Add zero padding to tree hash - #35
v0.1.0-alpha.1
Released 2018-02-05
Implements January pre-release spec
v0.1.0-alpha.0
Launched repository, claimed names for pip, RTD, github, etc