| Name | seriattrs JSON |
| Version |
2.2.0
JSON |
| download |
| home_page | https://github.com/Tesla2000/seriattrs |
| Summary | Unofficial extension of attrs ment to provided default serialization and deserialization options |
| upload_time | 2024-02-25 20:45:40 |
| maintainer | |
| docs_url | None |
| author | Tesla2000 |
| requires_python | >=3.5 |
| license | |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# SeriArrts module for automatic serialization and deserialization
SeriArrts is an unofficial extension to [attrs](https://www.attrs.org/) 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:
```bash
pip install seriattrs
```
### Example
Here's an example of how to use the serialization and deserialization with `SeriArrts`:
```python
@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`:
```python
@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
```python
@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)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/Tesla2000/seriattrs",
"name": "seriattrs",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.5",
"maintainer_email": "",
"keywords": "",
"author": "Tesla2000",
"author_email": "fratajczak124@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/62/21/96e9238be18fd629e6e782b5eda0b1ef848c0c90c11e70f7b044438fbf66/seriattrs-2.2.0.tar.gz",
"platform": null,
"description": "# SeriArrts module for automatic serialization and deserialization\n\nSeriArrts is an unofficial extension to [attrs](https://www.attrs.org/) library. \nThe module is ment to be used in conjunction with databases or json which may require serialization and deserialization.\nTo allow creation of custom Object-Database mapping DbAttrs supports basic datatype such as ints, uints, vars etc.\n\n## Installation\n\nYou can install the `seriattrs` package using pip:\n\n```bash\npip install seriattrs\n```\n\n### Example\n\nHere's an example of how to use the serialization and deserialization with `SeriArrts`:\n\n```python\n@define\nclass Bar(DbClass):\n dictionary: dict\n date: datetime\n decimal: Decimal\n\n@define\nclass Foo(DbClass):\n dictionary: dict\n date: datetime\n decimal: Decimal\n bar: Bar\n\nfoo = Foo({}, datetime.now(), Decimal(1), Bar({}, datetime.now(), Decimal(1)))\nserialized = foo.get_db_representation()\nfoo.bar = foo.bar._id\ntry:\n json.dump(serialized, sys.stdout)\nexcept:\n assert False\ndeserialized = Foo.from_dict(serialized)\nassert deserialized == foo\n```\n\nHere's an example of how to use the serialization and deserialization with `DbClassLiteral`:\n\n```python\n@define\nclass Bar(DbClassLiteral):\n dictionary: dict\n date: datetime\n decimal: Decimal\n\n@define\nclass Foo(DbClass):\n dictionary: dict\n date: datetime\n decimal: Decimal\n bar: Bar\n\nfoo = Foo({}, datetime.now(), Decimal(1), Bar({}, datetime.now(), Decimal(1)))\nserialized = foo.get_db_representation()\ntry:\n json.dump(serialized, sys.stdout)\nexcept:\n assert False\ndeserialized = Foo.from_dict(serialized)\nassert deserialized == foo\n```\n\nYou can make use of db_types the following way\n\n```python\n@define\nclass Foo(DbClass):\n a: int = int8()\n b: int = uint16()\n c: str = varchar(7)\n d: str = text()\n\n\nclass TestFooClass(unittest.TestCase):\n def setUp(self):\n self.foo_instance = Foo(0, 0, '', '')\n\n def test_attribute_a(self):\n with self.assertRaises(ValueError):\n self.foo_instance.a = -129 # Below int8 range\n with self.assertRaises(ValueError):\n self.foo_instance.a = 128 # Above int8 range\n\n def test_attribute_b_out_of_range(self):\n with self.assertRaises(ValueError):\n self.foo_instance.b = -1 # Below uint16 range\n with self.assertRaises(ValueError):\n self.foo_instance.b = 65536 # Above uint16 range\n\n def test_attribute_c_out_of_range(self):\n with self.assertRaises(ValueError):\n self.foo_instance.c = \"Too bigg\"\n\n def test_attribute_d_positive(self):\n passed_text = \"\"\"I'm the Scatman\nSki-bi dibby dib yo da dub dub\nYo da dub dub\nSki-bi dibby dib yo da dub dub\nYo da dub dub\n(I'm the Scatman)\nSki-bi dibby dib yo da dub dub\nYo da dub dub\nSki-bi dibby dib yo da dub dub\nYo da dub dub\nBa-da-ba-da-ba-be bop bop bodda bope\nBop ba bodda bope\nBe bop ba bodda bope\nBop ba bodda\nBa-da-ba-da-ba-be bop ba bodda bope\nBop ba bodda bope\nBe bop ba bodda bope\nBop ba bodda bope\"\"\"\n self.foo_instance.d = passed_text\n self.assertEqual(self.foo_instance.d, passed_text)\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "Unofficial extension of attrs ment to provided default serialization and deserialization options",
"version": "2.2.0",
"project_urls": {
"Homepage": "https://github.com/Tesla2000/seriattrs"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "de829b47f4a9f7976c7064f0d4f9546a87f2383312c283df758334c8958120f6",
"md5": "3632918d3c44509d95a7bdc9301183f0",
"sha256": "02d5b0fec5ccec41603938bbb475a538c571125bbb74cd126d1500c160f1fe24"
},
"downloads": -1,
"filename": "seriattrs-2.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3632918d3c44509d95a7bdc9301183f0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.5",
"size": 17831,
"upload_time": "2024-02-25T20:45:38",
"upload_time_iso_8601": "2024-02-25T20:45:38.375356Z",
"url": "https://files.pythonhosted.org/packages/de/82/9b47f4a9f7976c7064f0d4f9546a87f2383312c283df758334c8958120f6/seriattrs-2.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "622196e9238be18fd629e6e782b5eda0b1ef848c0c90c11e70f7b044438fbf66",
"md5": "a71da3c23d1a416b62550fb26c816f8c",
"sha256": "21bf286226fd62df3c09f443191d309175216efaedffccb99edd2237913b8fba"
},
"downloads": -1,
"filename": "seriattrs-2.2.0.tar.gz",
"has_sig": false,
"md5_digest": "a71da3c23d1a416b62550fb26c816f8c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.5",
"size": 11929,
"upload_time": "2024-02-25T20:45:40",
"upload_time_iso_8601": "2024-02-25T20:45:40.500927Z",
"url": "https://files.pythonhosted.org/packages/62/21/96e9238be18fd629e6e782b5eda0b1ef848c0c90c11e70f7b044438fbf66/seriattrs-2.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-25 20:45:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Tesla2000",
"github_project": "seriattrs",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "seriattrs"
}