Package: althaia
AlthaiaAlthaia:from Latin althaea, from Greek althaia - marsh mallow (literally: healing plant), from Greek althein to healWhat is it?Althaia is a very simple fork ofmarshmallow, with patches to improve the performance when dumping large sets
of data. It is then also compiled viacythonfor 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 originalupstream PRfor some discussion, or myoriginal announcement.How fast is it?It really depends on your data and usage, but using thebenchmark.pytest from the upstream marshmallow repo,
Althaia seems to shave off some ~30% of execution time on average. These values are an example test run results
from the upstream benchmark:Upstream(usec/dump)Althaia(usec/dump)Improvement(%)374.64258.61-30.9719189.8313275.84-30.81396368.67275365.67-30.52198163.58133714.07-32.52The table is the result of the following commands:python performance/benchmark.py
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 10000They are also available in this repo aspoetry run task upstream-performance. Note that you may get different
results while running the benchmarks (the numbers above were obtained with Althaia v3.20.1, generally speaking you
should be getting better results with newer versions, but sometimes not).Contribution into theserialization benchmarkis in the works (update:stalled), but
local run seems to be almost comparable toToasted 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.LibraryMany Objects (seconds)One Object (seconds)Relativeserpyco0.007676120.003891471Custom0.009657860.004676341.23917lima0.01169590.005836491.51564Pickle0.01376030.01368332.37246serpy0.03527280.01815084.61839Strainer0.05160050.02605066.71281Toasted Marshmallow0.0767920.041278610.207Althaia0.1018920.048421112.9943Colander0.2085140.10571927.1649Avro0.3037860.15118439.3314Lollipop0.3523310.17314145.4262Marshmallow0.5316360.27624369.8398Django REST Framework0.5311750.38752779.4203kim0.6697590.33613286.9576InstallationpipinstallalthaiaNOTE: This is still a work in progress and a wheel may not be available for your platform yet. PRs welcome!UsageThere 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:importalthaiaalthaia.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 marshmallowwill 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:fromalthaiaimportmarshmallow# or, e.g.fromalthaia.marshmallowimportSchemaThough I'm not sure why one would do that.Obviously, for allactualusage of marshmallow, you should always refer to the excellentmarshmallow docs.Bugs & ContributingIf 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 bugswillbe upstream bugs.Contributingmanylinuxbuilds for the CI pipeline is most welcome.When opening pull requests, please target thedevelopbranch by default.If you have any other ideas on how to tweak the performance, feel free to contribute in any way you can!Versioning & ReleasesAlthaia will always follow the upstream version of marshmallow to reduce confusion. In other words, Althaia versionX.Y.Zwill use marshmallow versionX.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 asX.Y.Z.N, whereNis the hotfix version.devreleases 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.DevelopingAlthaia is usingPoetrywith a custom build script, and sometaskipyscripts to facilitate things.
You can see them defined inpyproject.toml, or just typepoetry run task --list.Preparing a new version TL;DR:Editpyproject.tomland change the version of the packages for upstream marshmallow and Althaia itself.Runpoetry run task version-check.Runpoetry run task build.Runpoetry run task upstream-test.[Optional] Runpoetry run task upstream-performance.[Optional] Inspect the wheel content withpoetry run task inspect.Runpoetry run task publish-testto deploy to test PyPI.Known IssuesIf you have any marshmallow warnings ignored in yourpytest.ini, i.e. you havefilterwarningsset up
to ignore an error starting withmarshmallow.warnings, you will get an import error even if you're doingalthaia.patch()in yourconftest.py. As a workaround, you can change it to start withalthaia.marshmallow.warnings. This happens because pytest is trying to import marshmallow before Althaia
gets a chance to patch the importer.Since althaia 3.20.1, the support for python3.7 and 3.8 has been dropped, unlike marshmallow which has dropped
support only for python3.7. The reason for this are massive changes in typing annotation starting from python3.9,
which are no longer supported by the recently released Cython 3.0.0. Maintaining patches for 3.8 and 3.9+
would be difficult without being a significant time sink. Since python3.8 is already in security-updates-only state,
it's much easier to just drop it.