Skip to main content

SeriArrts module for automatic serialization and deserialization

SeriArrts is an unofficial extension to attrs library. The module is ment to be used in conjunction with databases or json which may require serialization and deserialization. To allow creation of custom Object-Database mapping DbAttrs supports basic datatype such as ints, uints, vars etc.

Installation

You can install the seriattrs package using pip:

pip install seriattrs

Example

Here's an example of how to use the serialization and deserialization with SeriArrts:

@define
class Bar(DbClass):
    dictionary: dict
    date: datetime
    decimal: Decimal

@define
class Foo(DbClass):
    dictionary: dict
    date: datetime
    decimal: Decimal
    bar: Bar

foo = Foo({}, datetime.now(), Decimal(1), Bar({}, datetime.now(), Decimal(1)))
serialized = foo.get_db_representation()
foo.bar = foo.bar._id
try:
    json.dump(serialized, sys.stdout)
except:
    assert False
deserialized = Foo.from_dict(serialized)
assert deserialized == foo

Here's an example of how to use the serialization and deserialization with DbClassLiteral:

@define
class Bar(DbClassLiteral):
    dictionary: dict
    date: datetime
    decimal: Decimal

@define
class Foo(DbClass):
    dictionary: dict
    date: datetime
    decimal: Decimal
    bar: Bar

foo = Foo({}, datetime.now(), Decimal(1), Bar({}, datetime.now(), Decimal(1)))
serialized = foo.get_db_representation()
try:
    json.dump(serialized, sys.stdout)
except:
    assert False
deserialized = Foo.from_dict(serialized)
assert deserialized == foo

You can make use of db_types the following way

@define
class Foo(DbClass):
    a: int = int8()
    b: int = uint16()
    c: str = varchar(7)
    d: str = text()


class TestFooClass(unittest.TestCase):
    def setUp(self):
        self.foo_instance = Foo(0, 0, '', '')

    def test_attribute_a(self):
        with self.assertRaises(ValueError):
            self.foo_instance.a = -129  # Below int8 range
        with self.assertRaises(ValueError):
            self.foo_instance.a = 128  # Above int8 range

    def test_attribute_b_out_of_range(self):
        with self.assertRaises(ValueError):
            self.foo_instance.b = -1  # Below uint16 range
        with self.assertRaises(ValueError):
            self.foo_instance.b = 65536  # Above uint16 range

    def test_attribute_c_out_of_range(self):
        with self.assertRaises(ValueError):
            self.foo_instance.c = "Too bigg"

    def test_attribute_d_positive(self):
        passed_text = """I'm the Scatman
Ski-bi dibby dib yo da dub dub
Yo da dub dub
Ski-bi dibby dib yo da dub dub
Yo da dub dub
(I'm the Scatman)
Ski-bi dibby dib yo da dub dub
Yo da dub dub
Ski-bi dibby dib yo da dub dub
Yo da dub dub
Ba-da-ba-da-ba-be bop bop bodda bope
Bop ba bodda bope
Be bop ba bodda bope
Bop ba bodda
Ba-da-ba-da-ba-be bop ba bodda bope
Bop ba bodda bope
Be bop ba bodda bope
Bop ba bodda bope"""
        self.foo_instance.d = passed_text
        self.assertEqual(self.foo_instance.d, passed_text)

Metadata

Release files for seriattrs 2.2.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 seriattrs 2.2.0
File Size Uploaded Provenance Actions
seriattrs-2.2.0.tar.gz 11.9 kB Without provenance Details for seriattrs-2.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for seriattrs 2.2.0
File Interpreter ABI Platform Actions
seriattrs-2.2.0-py3-none-any.whl Python 3 none any Details for seriattrs-2.2.0-py3-none-any.whl

Total release size: 29.8 kB

Release files / seriattrs-2.2.0.tar.gz

Download URL seriattrs-2.2.0.tar.gz
Size 11.9 kB
Tags Source
SHA-256 checksum
How to use checksums
21bf286226fd62df3c09f443191d309175216efaedffccb99edd2237913b8fba
BLAKE2b-256 checksum
How to use checksums
622196e9238be18fd629e6e782b5eda0b1ef848c0c90c11e70f7b044438fbf66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.1

Release files / seriattrs-2.2.0-py3-none-any.whl

Download URL seriattrs-2.2.0-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02d5b0fec5ccec41603938bbb475a538c571125bbb74cd126d1500c160f1fe24
BLAKE2b-256 checksum
How to use checksums
de829b47f4a9f7976c7064f0d4f9546a87f2383312c283df758334c8958120f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.1

Security for seriattrs 2.2.0

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.

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