Skip to main content

Fast YAML 1.2 Parser for Python 3.6+

Project description

🚀 zaml

Fast YAML 1.2 parsing library for Python 3.6+ 🐍

What's This?

Proof-of-concept for my PyCon DE 2022 talk, video, Speeding Up Python with Zig, not yet recommended for production use!

Library with the following objectives:

  • Written in pure Zig, importing Python.h headers directly, no FFI, ctypes or cffi.
  • Compiled using the Zig toolchain / CLI, no other tool (eg. clang) required.
  • Tested to be compatible with mac OSX, Linux and Windows.
  • Installable via PyPI
  • Should not require Zig toolchain locally in order to install and use.
  • Fastest available YAML 1.2 parser for Python.

Help wanted to achieve the full objectives, PRs welcome.

Installation

pip install zaml

Note: currently source distribution only, ie. sdist - no binary wheels (yet), therefore requires Zig 0.10.0 installed locally. Any other Zig version is untested.

Installing Locally

Some pre-requisites (linting etc.), pyenv also recommended:

pre-commit install
pre-commit run --all-files

The simplest possible extension module is a module with one function, that takes no arguments and returns an integer. This repo demonstrates a pure Zig module that does exactly that:

python -m venv .venv
source .venv/bin/activate
pip install -e .

Tests

Tests that the most basic possible Zig extension can in-fact be installed and returns the expected result:

python test.py

Benchmark

To run a benchmark of the current zaml prototype (also runs in CI and asserts that the YAML structure is correctly parsed):

cd benchmark
python benchmark.py

Results on my 2,3 GHz Quad-Core Intel Core i7 Mac:

Running benchmarks...

Benchmark results:
zaml took 0.89 seconds
PyYAML CSafeLoader took 13.36 seconds
ruamel took 38.86 seconds
PyYAML SafeLoader took 81.78 seconds

Credits

Would not exist without kubkon's, zig-yaml: https://github.com/kubkon/zig-yaml

Cross-platform Local Testing

Linux

To test in Linux, the easiest way is probably to use Docker:

docker run --name zaml -v $PWD:/root/zaml -it fedora

This kicks you into a shell in a running a container with this library mounted in the /root/zaml directory. Changes you make on your host machine will be immediately reflected in the container.

Install Python 3 headers, zig and test the library:

dnf install zig python3-devel
cd /root/zaml
python3 -m venv .venvlinux
source .venvlinux/bin/activate
pip install -e .

To re-attach to the container after exiting:

docker start -ia zaml

Windows

To test in Windows from a Mac, the easiest way I have found is to use Parallels.

MacOSX

I am writing this README on a Mac. Consequently, I have not attempted testing this library in MacOSX from another operating system host. If you manage this, please do add documentation about it here.

Publishing to PyPI

Note: Temporary instructions (until full CI setup).

You may need to upgrade build and twine (with your virtualenv activated):

python -m pip install --upgrade build
python -m pip install --upgrade twine

Then:

rm -rf dist
python3 -m build --sdist
python3 -m twine upload --repository pypi dist/*

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

zaml-0.0.9.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distributions

zaml-0.0.9-cp311-cp311-musllinux_1_1_x86_64.whl (29.4 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

zaml-0.0.9-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

zaml-0.0.9-cp310-cp310-musllinux_1_1_x86_64.whl (29.4 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

zaml-0.0.9-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.5 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

zaml-0.0.9-cp39-cp39-musllinux_1_1_x86_64.whl (29.4 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

zaml-0.0.9-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.5 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

zaml-0.0.9-cp38-cp38-musllinux_1_1_x86_64.whl (29.4 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

zaml-0.0.9-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.5 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

zaml-0.0.9-cp37-cp37m-musllinux_1_1_x86_64.whl (29.4 kB view hashes)

Uploaded CPython 3.7m musllinux: musl 1.1+ x86-64

zaml-0.0.9-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.5 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

zaml-0.0.9-cp36-cp36m-musllinux_1_1_x86_64.whl (29.5 kB view hashes)

Uploaded CPython 3.6m musllinux: musl 1.1+ x86-64

zaml-0.0.9-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (29.5 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.5+ x86-64

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