Giter Site home page Giter Site logo

attrs-serde's People

Contributors

jondot avatar tomsender avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

attrs-serde's Issues

no LICENSE

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.

Bump up dep constraints

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)

Cant build cytoolz

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 :
                               ^

Make `to` and `from` optional?

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": ...}?

recursively deserialize attributes

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.