jondot / attrs-serde Goto Github PK
View Code? Open in Web Editor NEWA serialization addon for attrs.
License: MIT License
A serialization addon for attrs.
License: MIT License
Last release lists the following. I haven't tested the codebase with more recent versions yet - but a new release with a minor bump would be helpful. Happy to colab.
Requires-Dist: attrs (>=19.1,<20.0)
Requires-Dist: cytoolz (>=0.9.0,<0.10.0)
Requires-Dist: toolz (>=0.9.0,<0.10.0)
Hi,
I'm trying to install your library on python3.9, but I get bunch of errors.
Though I can easily install cytoolz 0.11.0 version
Seems like updating dependencies will fix it.
Still want to use your library, but don't want to downgrade python version
ERROR: Command errored out with exit status 1: /home/asd/PycharmProjects/project/venv/bin/python -u -c 'import sys,
setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-fogixndl/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-fogixndl/setup.py'"'"';
f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__,
'"'"'exec'"'"'))' install --record /tmp/pip-record-ewz8g3qj/install-record.txt --single-version-externally-managed --compile --install-
headers /home/asd/PycharmProjects/project/venv/include/site/python3.9/cytoolz Check the logs for full command output.
cytoolz/functoolz.c:17307:45: error: ‘PyTypeObject {aka struct _typeobject}’ has no member named ‘tp_print’; did you mean ‘tp_dict’?
__pyx_type_7cytoolz_9functoolz_complement.tp_print = 0;
^~~~~~~~
tp_dict
In file included from /home/asd/.pyenv/versions/3.9.0/include/python3.9/unicodeobject.h:1026:0,
from /home/asd/.pyenv/versions/3.9.0/include/python3.9/Python.h:97,
from cytoolz/dicttoolz.c:17:
/home/asd/.pyenv/versions/3.9.0/include/python3.9/cpython/unicodeobject.h:446:26: note: declared here
static inline Py_ssize_t _PyUnicode_get_wstr_length(PyObject *op) {
^~~~~~~~~~~~~~~~~~~~~~~~~~
cytoolz/dicttoolz.c:9130:25: warning: ‘_PyUnicode_get_wstr_length’ is deprecated [-Wdeprecated-declarations]
(PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
^
import attr
from attrs_serde import serde
name_path = ["contact", "personal", "Name"]
phone_path = ["contact", "Phone"]
@serde
@attr.s(auto_attribs=True, frozen=True)
class Name:
first: str
last: str
@serde
@attr.s(auto_attribs=True, frozen=True)
class Person:
name: Name = attr.ib(metadata={"to": name_path, "from": name_path})
phone: str = attr.ib(metadata={"to": phone_path, "from": phone_path})
person_json = {"contact": {"personal": {"Name": {"first": "John", "last": "Smith"}}, "Phone": "555-112233"}}
# to/from only works on serde
p = Person(name=Name(first="John", last="Smith"), phone="555-112233")
print(p.to_dict())
# {'contact': {'personal': {'Name': {'first': 'John', 'last': 'Smith'}}, 'Phone': '555-112233'}}
p1 = Person.from_dict(person_json)
print(f"p1={p1}") # <---
# p1=Person(name={'first': 'John', 'last': 'Smith'}, phone='555-112233')
cattrs does the recursive right, but lack of attribute mapping.
attrs-serde has the mapping but does not do recursive deserialization.
One thing that confused me when trying out this library is that I was trying to serialize some existing models I had. All I was getting back from to_dict
was {}
. I didn't realize that the to
and from
metadata were required. Would it be acceptable if they weren't, and instead defaulted to the equivalent of [attr_name]
? So a model that contained a field phone = attr.ib()
would be serialized as a dict with {"phone": ...}
?
Hi, the README file points to a LICENSE
file that doesn't exist. I do see that your project.json and pyproject.yaml files say "license = MIT", but it's probably worth making that a bit more explicit.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.