Skip to main content

Marshmallow fork optimized for dumping speed.

Project description

Althaia

PyPI Version License PyPI Python

Althaia: from Latin althaea, from Greek althaia - marsh mallow (literally: healing plant), from Greek althein to heal

What is it?

Althaia is a very simple fork of marshmallow, with patches to improve the performance when dumping large sets of data. It is then also compiled via cython for some extra performance boost. Ideally, these patches will one day find their way into the upstream marshmallow in some cleaner form, and this package will become obsolete.

How does it work?

During the serialization process, marshmallow repeats a lot of lookup operations for each object it's attempting to serialize, even though these values never change during the single execution. The main patch in this repo is basically reading those values once and creating a serializer function, which is much more performant on large data sets.

The entire thing is then compiled into C extension modules and released only as binary wheels.

Check out the original upstream PR for some discussion.

How fast is it?

It really depends on your data and usage, but using the benchmark.py test from the upstream marshmallow repo, Althaia seems to shave off some ~45% of execution time on average. These values are an example test run results from the upstream benchmark:

Upstream(usec/dump) Althaia(usec/dump) Improvement(%)
22672.54 11969.85 52.80
463016.55 267486.80 57.78
231068.86 128756.36 55.72

The table is the result of the following commands:

python performance/benchmark.py --object-count 1000
python performance/benchmark.py --iterations=5 --repeat=5 --object-count 20000
python performance/benchmark.py --iterations=10 --repeat=10 --object-count 10000

They are also available in this repo as poetry run task upstream-performance.

Contribution into the serialization benchmark is in the works, but local run seems to be almost comparable to Toasted Marshmallow, which is stuck on an old marshmallow 2.x branch. This means that Althaia gives you (almost) the speed of Toasted Marshmallow, with all the goodies of the latest marshmallow.

Library Many Objects (seconds) One Object (seconds) Relative
serpyco 0.00767612 0.00389147 1
Custom 0.00965786 0.00467634 1.23917
lima 0.0116959 0.00583649 1.51564
Pickle 0.0137603 0.0136833 2.37246
serpy 0.0352728 0.0181508 4.61839
Strainer 0.0516005 0.0260506 6.71281
Toasted Marshmallow 0.076792 0.0412786 10.207
Althaia 0.101892 0.0484211 12.9943
Colander 0.208514 0.105719 27.1649
Avro 0.303786 0.151184 39.3314
Lollipop 0.352331 0.173141 45.4262
Marshmallow 0.531636 0.276243 69.8398
Django REST Framework 0.531175 0.387527 79.4203
kim 0.669759 0.336132 86.9576

Installation

pip install althaia

NOTE: This is still a work in progress and a wheel may not be available for your platform yet. PRs welcome!

Usage

There are two ways to use Althaia: as a standalone package, or as a drop-in replacement for marshmallow. Latter method is the recommended one. Add the following code as early as possible in your app bootstrap:

import althaia
althaia.patch()

This will install a Python meta path importer which will mimic marshmallow for the rest of your project, without any changes to the codebase, i.e. import marshmallow will work as expected. If and when this package becomes obsolete, there will be no need to change the rest of your source to revert to upstream marshmallow.

Alternatively, you can use Althaia directly:

from althaia import marshmallow
# or, e.g.
from althaia.marshmallow import Schema

Though I'm not sure why one would do that.

Obviously, for all actual usage of marshmallow, you should always refer to the excellent marshmallow docs.

Bugs & Contributing

If there are bugs, please make sure they are not upstream marshmallow bugs before reporting them. Since the patches applied are picking apart some of the marshmallow internals, any breakage should be immediately visible, and the chances are that most bugs will be upstream bugs.

Contributing manylinux builds for the CI pipeline is most welcome.

If you have any other ideas on how to tweak the performance, feel free to contribute in any way you can!

Versioning & Releases

Althaia will always follow the upstream version of marshmallow to reduce confusion. In other words, Althaia version X.Y.Z will use marshmallow version X.Y.Z.

Additionally, if it comes to some changes on Althaia side (repo structure, build process, bugfixes), PEP440 will be followed and will be released either as alpha, beta, rc (X.Y.ZaN, X.Y.ZbN, X.Y.ZrcN) if there is still no change in the upstream dependency, or post-releases (X.Y.ZpostN). Since bugfixing is discouraged for post-releases, there may also be a hotfix release as X.Y.Z.N, where N is the hotfix version.

dev releases may appear on test PyPI (X.Y.Z.devN), but these are not relevant to the general public.

There will obviously be some delay between marshmallow and Althaia releases, and it is inevitable that I will get sloppy over time, so feel free to create a GitHub issue if you need an urgent update to latest marshmallow.

Developing

Althaia is using Poetry with a custom build script, and some taskipy scripts to facilitate things. You can see them defined in pyproject.toml, or just type poetry run task --list.

Preparing a new version TL;DR:

  • Edit pyproject.toml and change the version of the packages for upstream marshmallow and Althaia itself.
  • Run poetry run task version-check.
  • Run poetry run task build.
  • Run poetry run task upstream-test.
  • [Optional] Run poetry run task upstream-performance.
  • [Optional] Inspect the wheel content with poetry run task inspect.
  • Run poetry run task publish-test to deploy to test PyPI.

Known Issues

  • If you have any marshmallow warnings ignored in your pytest.ini, i.e. you have filterwarnings set up to ignore an error starting with marshmallow.warnings, you will get an import error even if you're doing althaia.patch() in your conftest.py. As a workaround, you can change it to start with althaia.marshmallow.warnings. This happens because pytest is trying to import marshmallow before Althaia gets a chance to patch the importer.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

althaia-3.14.1a2.tar.gz (49.4 kB view details)

Uploaded Source

Built Distributions

althaia-3.14.1a2-cp310-cp310-win_amd64.whl (758.7 kB view details)

Uploaded CPython 3.10 Windows x86-64

althaia-3.14.1a2-cp310-cp310-musllinux_1_1_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

althaia-3.14.1a2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

althaia-3.14.1a2-cp310-cp310-macosx_10_15_x86_64.whl (980.9 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

althaia-3.14.1a2-cp39-cp39-win_amd64.whl (754.9 kB view details)

Uploaded CPython 3.9 Windows x86-64

althaia-3.14.1a2-cp39-cp39-musllinux_1_1_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

althaia-3.14.1a2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

althaia-3.14.1a2-cp39-cp39-macosx_10_15_x86_64.whl (980.0 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

althaia-3.14.1a2-cp38-cp38-win_amd64.whl (766.5 kB view details)

Uploaded CPython 3.8 Windows x86-64

althaia-3.14.1a2-cp38-cp38-musllinux_1_1_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

althaia-3.14.1a2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

althaia-3.14.1a2-cp38-cp38-macosx_10_15_x86_64.whl (956.5 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

Details for the file althaia-3.14.1a2.tar.gz.

File metadata

  • Download URL: althaia-3.14.1a2.tar.gz
  • Upload date:
  • Size: 49.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for althaia-3.14.1a2.tar.gz
Algorithm Hash digest
SHA256 16559d9e527f79633b3dd30f1804afb559a22e5960074cfc27c572982d380983
MD5 f22ec6b6757cb0772f7da17ac47b4042
BLAKE2b-256 4ed13dca747490af24522d1efdd0f6af7f47a93c0b0dcdcd560ceec3a60fa685

See more details on using hashes here.

File details

Details for the file althaia-3.14.1a2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: althaia-3.14.1a2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 758.7 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for althaia-3.14.1a2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ea3a881db5a3aba1201fb64a755a03c43d31faac8c85d4236085e5b40438b759
MD5 44e614d8532b1e682c49a0dd32d59fe6
BLAKE2b-256 e084778017a7becd8a1f5c8faf342d1cdf480206e928e4b75a1e1ccce60b36d7

See more details on using hashes here.

File details

Details for the file althaia-3.14.1a2-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

  • Download URL: althaia-3.14.1a2-cp310-cp310-musllinux_1_1_x86_64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.10, musllinux: musl 1.1+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for althaia-3.14.1a2-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 6c5c897a484d4ace8107bf1deed9b8cff0f92c860deb5e3a1ec91d99c23e456d
MD5 6c802e4ae85a892646bb28db99500890
BLAKE2b-256 0ef79b03cf223152a96cb9b7b9a27efcfa4fb07a6305ae6add390ace0c557dc9

See more details on using hashes here.

File details

Details for the file althaia-3.14.1a2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for althaia-3.14.1a2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a6917cfcd9d96b8812a3537fb39d55fb29073f948f92381d6409224263f411fd
MD5 43edc7f6ba1825216f47a2d7d1873bdd
BLAKE2b-256 f6035c6beb88814d75bba7a59796fc788dffe51c8c6fd4b133ce5679deb1f3e9

See more details on using hashes here.

File details

Details for the file althaia-3.14.1a2-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: althaia-3.14.1a2-cp310-cp310-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 980.9 kB
  • Tags: CPython 3.10, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for althaia-3.14.1a2-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 939ea3a99bd52a54db4ad117907df2eec564dc6f74d84fa64e4c3461be792825
MD5 da796af96b26ab6d8bfab7213e1585e6
BLAKE2b-256 d36025c4b07dda014e7f44414ce0e5eb40cbb5097eb1b70f0b2105fa4c3eb0b5

See more details on using hashes here.

File details

Details for the file althaia-3.14.1a2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: althaia-3.14.1a2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 754.9 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for althaia-3.14.1a2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8ae9a5a5dea9bc6b2be981b30c5fe625c70137c32d0859d179973c4d8ad3e45d
MD5 927c9ed3b9e8b03d488e94ec8a9672d2
BLAKE2b-256 669f183bc0949d9cd951167699e4c63b3f9f1f439617f952c1442658cc8fa227

See more details on using hashes here.

File details

Details for the file althaia-3.14.1a2-cp39-cp39-musllinux_1_1_x86_64.whl.

File metadata

  • Download URL: althaia-3.14.1a2-cp39-cp39-musllinux_1_1_x86_64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.9, musllinux: musl 1.1+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for althaia-3.14.1a2-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 0a23025725fe8dcb97a035886d9ac9845afe472a42750a627aa2a6cce60642ac
MD5 bdd959a89a7034545e92e117827bbe05
BLAKE2b-256 61aef3e6c4ee2f97aa9ec9f37e7383b51d3b582207061737e904191cccc04f6c

See more details on using hashes here.

File details

Details for the file althaia-3.14.1a2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for althaia-3.14.1a2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 59614c66a9d3e3bb0cfb4c17b74589a610b0c90ecfd227514a6ab8a889c44375
MD5 3b9a7f810d366fae6a14c5edb287d3f8
BLAKE2b-256 de7210feefc9a0239e09c2c5bcfe9ea2f63fb78889e2681f31c8e0c08b098d2f

See more details on using hashes here.

File details

Details for the file althaia-3.14.1a2-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: althaia-3.14.1a2-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 980.0 kB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for althaia-3.14.1a2-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 0964d3419605bfa7f2989afb5391684a7813835738854c044243ae8c0b1a23f2
MD5 f4a0bf49fc935e1bf5e2f98b303b5796
BLAKE2b-256 444ea4c0ff3204ccb70cb67dc88b83f547245005f86e55f3d7419fb025ab78cb

See more details on using hashes here.

File details

Details for the file althaia-3.14.1a2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: althaia-3.14.1a2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 766.5 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for althaia-3.14.1a2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 910ab3b53cb62da80096555dc5a392646bc5a29290c796376bde92dd1c3630be
MD5 a65a97d2338b94d9eb1fe1b12db053ff
BLAKE2b-256 e2c515b2111386d8d52c94ef3a894a37cbfe055ddd6bebf737774eebcd71e961

See more details on using hashes here.

File details

Details for the file althaia-3.14.1a2-cp38-cp38-musllinux_1_1_x86_64.whl.

File metadata

  • Download URL: althaia-3.14.1a2-cp38-cp38-musllinux_1_1_x86_64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.8, musllinux: musl 1.1+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for althaia-3.14.1a2-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 253b8a48bbbbf871cf95482c90d842ccb338412eb5e2114fcf9ad50ecf225568
MD5 1cae509c985caf614734bf7218c4b132
BLAKE2b-256 3ce157ddb4b6a038c5416dc9228911d2ee8d3b138701b1ffc5844c37aaba2945

See more details on using hashes here.

File details

Details for the file althaia-3.14.1a2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for althaia-3.14.1a2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 24a26660252e6a7d33afd1a063227deda529e2b7e44aa6e812efb93d1d0ea92c
MD5 b8e2fe05d507138afdcdeabf2537aea4
BLAKE2b-256 44502b9f63ceadf7e8b13b7ccfe2a650fd77a2bb695071c2f0510045511effe5

See more details on using hashes here.

File details

Details for the file althaia-3.14.1a2-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

  • Download URL: althaia-3.14.1a2-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 956.5 kB
  • Tags: CPython 3.8, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for althaia-3.14.1a2-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 53bd3c1745ffac8dba79bae686fcc0ed9ee83e01bf14adf55efd4016ef168dce
MD5 f39dcb7c826dc169f4dd51aebe1adc7d
BLAKE2b-256 44bc5b3f85afe1f12083a6fde6d0bc09b3308c7b77aeb6e9b3750c651a3625ce

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page