pys

pyserde

pypi i pyserde

42 Versions

0.9.2

1 month ago
  • chore: Bump allowed version of numpy to >1.21.0 on Python 3.7 (beb2a8b)
  • fix: Fix deserialization of optional complex types with default=None (2b3b7ae)

This release had contributions from 1 person: @kmsquire. Thank you so much! 🎉 😂


0.9.1

1 month ago
  • fix: Call to untyped function "serde" in typed context (84c5f07)

0.9.0

1 month ago

pyserde v0.9 adds one of the most awaited features, the type checking functionality 🎉 If you add Coerce or Strict in serde decorator, pyserde will do type coercing or type checking based on the declared types.

Coerce

Type coercing automatically converts a value into the declared type during (de)serialization. If the value is incompatible e.g. value is "foo" and type is int, pyserde raises an SerdeError.

@serde(type_check=Coerce)
@dataclass
class Foo
    s: str

foo = Foo(10)
# pyserde automatically coerce the int value 10 into "10".
# {"s": "10"} will be printed.
print(to_json(foo))
Strict

Strict type checking is to check every value against the declared type during (de)serialization. We plan to make Strict a default type checker in the future release.

@serde(type_check=Strict)
@dataclass
class Foo
    s: str

foo = Foo(10)
# pyserde checks the value 10 is instance of `str`.
# SerdeError will be raised in this case because of the type mismatch.
print(to_json(foo))
  • refactor: Change default type_check from Coerce to NoCheck (23ea180)
  • refactor: Change to pass "type_check" parameter in decorator (fbe8dc8)
  • feat: Add type coercion feature make it default (dabb777)
  • feat: Implement strict type checking (0273b9a)

Another notable change is switching toml library from toml to tomli. tomli is used in a handful of major products e.g. pip and pytest and will be the part of Python standard library in Python 3.11.

  • feat: Switch toml library to tomli (11b4df6)
  • Better documentation about generic alias (fd4e5a5)
  • Ensure union_func_name produces a valid function name (eddf250)
  • Import 'Literal' from serde.compat (a7450c1)
  • Support NumPy 1.23 in Python 3.7/3.8 (3309a73)
  • Use str instead of repr in typename, fixing Union[Literal["str"], ...] (b3905ef)
  • fix: from_json return returns T not Optional[T] (9e50fb7)

This release had contributions from 1 person: @kngwyu. Thank you so much! 🎉 😂


0.8.3

3 months ago
  • fix: Use numpy<1.23.0 for python 3.7 and 3.8 (3045521)

0.8.2

4 months ago
0.8.2 (2022-06-18)
  • chore: Replace stringcase with casfey (1f8a17d), closes #240

This release had a contribution from 1 person: @gitpushdashf. Thank you so much! 🎉 😂


0.8.1

4 months ago
  • feat: Don't wrap user exception in SerdeError (161cffd)

0.8.0

4 months ago

Thanks to the contribution by @kigawas, pyserde can optionally use orjson as JSON serializer!

pip install pyserde[orjson]

If orjson is installed in the system, pyserde automatically use orjson in to_json/from_json.

NOTE: In order to align the JSON (de)serializer to orjson, a few parameters are passed in json.dumps internally. This would lead to a breaking change in some cases. If you need the same behaviour as in pyserde<0.8, please explicitely pass those parameters in serde.json.to_json. 🙇‍♂️

to_json(obj, ensure_ascii=True, separators=(", ", ": "))

Other noteble chage is we have @dataclass decorator back in the all example and test code in the repository as shown below. It's because we found mypy isn't able to deduce the type correctly without @dataclass decorator. If you are not mypy user, you can still declare a class with only @serde decorator. 👍 For more information, please read the docs.

@serde
@dataclass  # <-- Recommended to add @dataclass if you are mypy user.
class Foo:
    i: int
    s: str
    f: float
    b: bool
  • build: Add "orjson" extras (ea70ec1)
  • orjson support (2744675)
  • Update json.py (2d67b65)
  • feat: Support class declaration w/wo dataclass (a35f909)
  • fix: Add dataclass decorator for all example code (60567ab)
  • fix: Treat |None as Optional (5555452)
  • Fix the default deserializer for custom class deserializer (6c2245b)

This release had contributions from 1 person: @kigawas. Thank you so much! 🎉 😂


0.7.3

5 months ago

Thanks to the great contribution by @kmsquire, pyserde supports some numpy types!

@serde
class NPFoo:
    i: np.int32
    j: np.int64
    f: np.float32
    g: np.float64
    h: np.bool_
    u: np.ndarray
    v: npt.NDArray
    w: npt.NDArray[np.int32]
    x: npt.NDArray[np.int64]
    y: npt.NDArray[np.float32]
    z: npt.NDArray[np.float64]
  • feat: Remove try-catch from is_numpy_array() (unnecessary) (731876f)
  • feat: Support Literal[...] type annotation (e50c958)
  • feat: Support numpy types (78eb22e)
  • feat(compat): Only define np_get_origin() for python 3.8 or earlier (02c5af2)
  • feat(numpy): Support serialization of numpy.datetime64 (5e521cf)
  • Don't import tests module from pyserde package (d664426)
  • fix: Recognized numpy arrays on Python 3.7, 3.8 (a0fa36f)
  • fix(numpy): Fix direct numpy array deserialization (8f9f71c)
  • ci: Remove pypy-3.8 until a numpy wheel is released for it (61b6130)
  • chore: Update black, fix test_union formatting (4a708fd)
  • chore: Update numpy version specification based on numpy compatibility with python (1fa5e07)

This release had contributions from 2 people: @kmsquire and @chagui. Thank you so much! 🎉 😂


0.7.2

6 months ago
  • Don't package tests and examples (af829ae), closes #214
  • ci: Use pypy-3.8 (316b98e)
  • feat: Support PEP604 Union operator (17419d2)

This release had contributions from 1 person: @gitpushdashf. Thank you so much! 🎉 😂


0.7.1

7 months ago
  • ci: Run tests on pull_request only (015cb41)
  • feat: Support typing.Generic (e9f2bdb)
  • build: Drop python 3.6 and pypy (279f1a4)
  • docs: Fix typo in docs introduction (03f24da)

This release had contributions from 1 person: @chagui. Thank you so much! 🎉 😂


0.7.0

8 months ago
  • fix: Optional in custom class deserializer (181b2f1)
  • fix: raise SerdeError from serde's APIs (76b0aee)
    • pyserde (de)serialize method used to raise various Exceptions such as KeyError. pyserde always raises SerdeError since v0.7.0
  • core: using black formatting only if debug is enabled (e596a84)
  • feat: Add _make_serialize and _make_deserialize (a71c5d5)
  • feat: Implement Union tagging system (c884dc4)
    • This will change the default tagging for dataclasses with Union from Untagged to ExternalTagging. This may break the existing code, so please be aware if you use dataclasses with Union. For more information, check the documentation
  • build: Update mypy to workaround typed_ast error (0ea33a7)

This release had contributions from 1 person: @tardyp. Thank you so much! 🎉 😂


0.6.0

10 months ago
  • feat: Add @serde decorator (523dc9c)
  • feat: Add serde field function (488bf00)
  • feat: Add serde_skip_default field attribute (0f0b212)
  • feat: Automatically put dataclass decorator (2f0cf01)

With serde decorator and field function, you can declare pyserde class more easily.

from serde import serde, field

@serde
class Foo:
    a : List[str] = field(default_factory=list, skip_if_false=True)

The declaration until v0.5.3 still works.

from dataclasses import dataclass
from serde import serialize, deserialize

@deserialize
@serialize
@dataclass
class Foo:
    a : List[str] = field(default_factory=list, metadata={'serde_skip_if_false': True})

0.5.3

10 months ago
  • feat: Add more dataclass Field's attrs to Field (7b57c53)
  • feat: Support python 3.10 (2f0c557)
  • refactor: Delete unused imports (629d040)
  • refactor: Remove type references from SerdeScope (bdd8784)
  • refactor: Speficy correct type bound for serde.core.fields (c3b555c)
  • fix: Add types in typing module to scope (e12e802)
  • fix: Never use default value for from_tuple (3ce4f6b)
  • fix: Use default value only if key isn't present (3fa4ab6)
  • Fix typo in README (5f957d0)

This release had contributions from 2 people: @rnestler, @mauvealerts. Thank you so much! 🎉 😂


0.5.2

1 year ago
  • feat: (de)serialize non dataclass types correctly (0ffb9ea)
  • refactor: Fix minor type error (bef0c4f)
  • refactor: Remove unused imports (cc16d58)
  • refactor: Use backports-datetime-fromisoformat for python 3.6 (014296f)
  • build: Remove unused dependency for examples (3a5ca01)

0.5.1

1 year ago
  • feat: deserialize to the type more correctly (a4c155c)
  • refactor: import minimum names (f242a93)

0.5.0

1 year ago
@deserialize
@serialize
@dataclass
class Bar:
    c: float
    d: bool

@deserialize
@serialize
@dataclass
class Foo:
    a: int
    b: str
    bar: Bar = field(metadata={'serde_flatten': True})

This release had contributions from 1 person: @alexmisk. Thank you so much! 🎉 😂


0.4.0

1 year ago
  • feat: add support for lazy annotations PEP563 (#112) (f7f6996), closes #112
from __future__ import annotations
from dataclasses import dataclass
from serde import deserialize, serialize

@deserialize
@serialize
@dataclass
class Foo:
    i: int
    s: str
    f: float
    b: bool

    def foo(self, cls: Foo):  # You can use "Foo" type before it's defined.
        print('foo')
  • feat: Implement custom class (de)serializer (3484d46)
  • feat: Implement custom field (de)serializer (14b791c)
def serializer(cls, o):
    ...

def deserializer(cls, o):
    ...

@deserialize(deserializer=deserializer)
@serialize(serializer=serializer)
@dataclass
class Foo:
    i: int
    # Class serializer/deserializer is used as default.
    dt1: datetime
    # Override by field serializer/deserializer.
    dt2: datetime = field(
        metadata={
            'serde_serializer': lambda x: x.strftime('%y.%m.%d'),
            'serde_deserializer': lambda x: datetime.strptime(x, '%y.%m.%d'),
        }
    )
  • feat: Improve error description for union type (8abb549)
  • feat: Improve serde.inspect (8b8635a)
  • feat: Support typing.any (988a621)
  • feat: Support typing.NewType for primitives (731ed79)
  • refactor: Add lvalue renderer for serialization (665dc77)
  • refactor: Remove arg template filter from se.py (0377655)
  • refactor: Remove self class from scope (da81f1f)
  • refactor: Rename custom (de)serializer attributes (03b2274)
  • ci: Add python 3.10-dev to CI pipeline (1f33e59)
  • ci: Don't cache pip to workaround pip error (c912429)
  • build: add pre-commit to test requirements (a88ea40)
  • fix: correctly render single element tuples (a8a6456)
  • fix: pass convert_sets argument to union functions (ab40cc9)
  • fix: support unions with nested unions in containers (#113) (c26e828), closes #113

0.3.2

1 year ago
  • feat: Improve error description for union type (8abb549)
  • feat: Improve serde.inspect (8b8635a)
  • feat: Support typing.any (988a621)
  • feat: Support typing.NewType for primitives (731ed79)
  • build: add pre-commit to test requirements (a88ea40)
  • fix: correctly render single element tuples (a8a6456)
  • fix: pass convert_sets argument to union functions (ab40cc9)
  • fix: support unions with nested unions in containers (#113) (c26e828), closes #113
  • ci: Don't cache pip to workaround pip error (c912429)
  • refactor: Remove self class from scope (da81f1f)

This release had contibutions from 1 person: @ydylla. Thank you so much! 🎉 😂


0.3.1

2 years ago
  • fix: Add type annotation to serde decorators (f885a27)

You can get the code completion from the class with serialize and deserialize decorators. I would recommend everyone to upgrade to v0.3.1.


0.3.0

2 years ago
  • feat: Support PEP585 type hint annotation (81d3f4f)
    @deserialize
    @serialize
    @dataclass
    class Foo:
        l: list[str]
        t: tuple[str, bool]
        d: dict[str, list[int]]
    
  • feat: add support for typing.Set & set (20a4cdc)
  • feat: add more types & use code generation (d352d2d)
    • IPv4Address, IPv6Address, IPv4Network, IPv6Network, IPv4Interface, IPv6Interface
    • PosixPath, WindowsPath, PurePath, PurePosixPath, PureWindowsPath
    • UUID
  • feat: add convert_sets option required for to_json & to_msgpack (f954586)
  • feat: add union support for complex types (434edf6)
    @deserialize
    @serialize
    @dataclass
    class Foo:
        v: Union[int, str]
        c: Union[Dict[str, int], List[int]]
    
  • fix: Ellipsis overwriting configured default for reuse_instances (b0366e5)
  • fix: forward reuse_instances & fix call order for optionals (c56128c)
  • fix: compatibility with python 3.6 (7ae87b4)
  • fix: this pytest option does not exist #58 (c5938da), closes #58
  • fix: scope should not be shared between classes (889ada1)
  • fix: use iter_unions to recursively collect all unions of dataclass (577aeb9)
  • build: Add PEP561 py.typed marker file (c0f46b9)
  • build: Don't install dataclasses for python>3.6 (f47caa9)
  • build: setup pre-commit as formatting tool (2876de4)
  • ci: add code style check (c52f7e9)

This release had contibutions from 2 people: @ydylla, @alexmisk. Thank you so much! 🎉 😂


0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

4 years ago

42 Versions

TagPublished
0.9.21mo ago
0.9.11mo ago
0.9.01mo ago
0.8.33mos ago
0.8.24mos ago
0.8.14mos ago
0.8.04mos ago
0.7.35mos ago
0.7.26mos ago
0.7.17mos ago
0.7.08mos ago
0.6.010mos ago
0.5.310mos ago
0.5.21yr ago
0.5.11yr ago
0.5.01yr ago
0.4.01yr ago
0.3.21yr ago
0.3.12yrs ago
0.3.02yrs ago
0.2.22yrs ago
0.2.12yrs ago
0.2.02yrs ago
0.1.52yrs ago
0.1.42yrs ago
0.1.32yrs ago
0.1.22yrs ago
0.1.12yrs ago
0.1.03yrs ago
0.0.133yrs ago
0.0.123yrs ago
0.0.113yrs ago
0.0.103yrs ago
0.0.93yrs ago
0.0.83yrs ago
0.0.73yrs ago
0.0.63yrs ago
0.0.53yrs ago
0.0.43yrs ago
0.0.33yrs ago
0.0.23yrs ago
0.0.14yrs ago