Skip to content

Releases: yukinarit/pyserde

v0.9.2

03 Sep 11:31
88be343
Compare
Choose a tag to compare
  • 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! 🎉 😂

v0.9.1

30 Aug 13:49
1f48c9c
Compare
Choose a tag to compare
  • fix: Call to untyped function "serde" in typed context (84c5f07)

v0.9.0

26 Aug 14:32
d42e058
Compare
Choose a tag to compare

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! 🎉 😂

v0.8.3

28 Jun 12:46
e313fa8
Compare
Choose a tag to compare
  • fix: Use numpy<1.23.0 for python 3.7 and 3.8 (3045521)

v0.8.2

18 Jun 02:32
90c0871
Compare
Choose a tag to compare
  • chore: Replace stringcase with casfey (1f8a17d), closes #240

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

v0.8.1

15 Jun 00:06
ace00ad
Compare
Choose a tag to compare
  • feat: Don't wrap user exception in SerdeError (161cffd)

v0.8.0

01 Jun 22:50
0421050
Compare
Choose a tag to compare

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! 🎉 😂

v0.7.3

10 May 14:38
508c54d
Compare
Choose a tag to compare

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! 🎉 😂

v0.7.2

11 Apr 22:17
0963c35
Compare
Choose a tag to compare
  • 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! 🎉 😂

v0.7.1

17 Mar 13:45
924671d
Compare
Choose a tag to compare
  • 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! 🎉 😂