Skip to main content
https://github.com/brunonicko/estruttura/workflows/MyPy/badge.svg https://github.com/brunonicko/estruttura/workflows/Lint/badge.svg https://github.com/brunonicko/estruttura/workflows/Tests/badge.svg https://readthedocs.org/projects/estruttura/badge/?version=stable https://img.shields.io/github/license/brunonicko/estruttura?color=light-green https://static.pepy.tech/personalized-badge/estruttura?period=total&units=international_system&left_color=grey&right_color=brightgreen&left_text=Downloads https://img.shields.io/pypi/pyversions/estruttura?color=light-green&style=flat

Overview

Abstract data structures.

Motivation

estruttura was born out of the need for a similar interface between the datta and objetto packages.

Relationship

estruttura provides a Relationship class that contains information about the values stored in the Structures, such as typing (with support for runtime type checking), serialization, validation, conversion, etc.

>>> from six import string_types
>>> from estruttura import Relationship, exceptions
>>> def converter(value):
...     if isinstance(value, string_types) and "." in value:
...         return float(value)
...     elif not isinstance(value, float):
...         return int(value)
...
>>> def validator(value):
...     if value > 10:
...         raise exceptions.ValidationError(value)
...
>>> relationship = Relationship(types=(int, float), converter=converter, validator=validator)
>>> relationship.process_value("3.3")
3.3

Structures

estruttura offers all the class combinations of the concepts described below.

Private Structure

Holds data internally and only allow for changes privately.

User Structure

Allows for changing of the data by external clients (public).

Immutable Structure

Only allows data changes through copying. Immutable structures are hashable.

>>> from estruttura.examples import ImmutableList
>>> l_a = ImmutableList()
>>> l_b = l_a.extend(range(3))
>>> list(l_b) == [0, 1, 2]
True

Mutable Structure

Allows in-place data changes. Mutable structures are not hashable.

>>> from estruttura.examples import MutableList
>>> l = MutableList()
>>> l.extend(range(3))
>>> list(l) == [0, 1, 2]
True

Dict Structure

Dictionary-like data structure class.

>>> from estruttura import Relationship
>>> from estruttura.examples import MutableDict
>>> class StrIntDict(MutableDict):
...     relationship = Relationship(converter=str)
...     value_relationship = Relationship(converter=int)
...
>>> StrIntDict({1: "1"})
StrIntDict({'1': 1})

List Structure

List-like data structure class.

>>> from estruttura import Relationship
>>> from estruttura.examples import MutableList
>>> class IntList(MutableList):
...     relationship = Relationship(converter=int)
...
>>> IntList(["1", 1, 1.0])
IntList([1, 1, 1])

Set Structure

Set-like data structure class.

>>> from estruttura import Relationship
>>> from estruttura.examples import MutableSet
>>> class IntSet(MutableSet):
...     relationship = Relationship(converter=int)
...
>>> IntSet({"1", 1, 1.0})
IntSet({1})

Structure

Dataclass-like structure class that has a schema defined by attributes.

>>> import math
>>> from estruttura import Attribute, Relationship, getter
>>> from estruttura.examples import ImmutableClass
>>> class Point(ImmutableClass):
...     x = Attribute()
...     y = Attribute()
...     d = Attribute(serializable=True, repr=True)
...     @getter(d, dependencies=(x, y))
...     def _(self):
...         return math.sqrt(self.x**2 + self.y**2)
...
>>> Point(3, 4)
Point(3, 4, <d=5.0>)
>>> Point(3, 4).serialize() == {"x": 3, "y": 4, "d": 5.0}
True
>>> Point.deserialize({"x": 3, "y": 4})
Point(3, 4, <d=5.0>)

Release files for estruttura 4.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for estruttura 4.0.0
File Size Uploaded
estruttura-4.0.0.tar.gz 50.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for estruttura 4.0.0
File Interpreter ABI Platform
estruttura-4.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 94.2 kB

Release files / estruttura-4.0.0.tar.gz

Download URL estruttura-4.0.0.tar.gz
Size 50.5 kB
Tags Source
SHA-256 checksum
How to use checksums
bf769b4dc79ee8252e777801f1f6a7f2dc30a3c977a9f100021e5024d46a8b21
BLAKE2b-256 checksum
How to use checksums
5add144e00154e02f64c12cbf85071220ab9f25cd9b17c8771802fbecb1fc108
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / estruttura-4.0.0-py2.py3-none-any.whl

Download URL estruttura-4.0.0-py2.py3-none-any.whl
Size 43.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
bb7d81d7cf11902b9a8ed2d6b8c519819f12003f273f8d0e87d5619d0a451e73
BLAKE2b-256 checksum
How to use checksums
9b91d97e001fcad7008b31c50f12b74421603e48a1827697e88f4c0f841c41f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

4.0.0 This release

2 release files

3.0.0

2 release files

2.0.0

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page