Skip to main content

A better C API for Python

Project description

HPy: a better API for Python

Build Documentation Join the discord server at https://discord.gg/xSzxUbPkTQ

Website: hpyproject.org
Community: HPy Discord server
Mailing list: hpy-dev@python.org

Summary

HPy is a better API for extending Python in C. The old C API is specific to the current implementation of CPython. It exposes a lot of internal details which makes it hard to:

  • implement it for other Python implementations (e.g. PyPy, GraalPy, Jython, IronPython, etc.).
  • experiment with new things inside CPython itself: e.g. using a GC instead of refcounting, or to remove the GIL
  • guarantee binary stability

HPy is a specification of a new API and ABI for extending Python that is Python implementation agnostic and designed to hide and abstract internal details such that it:

  • can stay binary compatible even if the underlying Python internals change significantly
  • does not hinder internal progress of CPython and other Pythons

Please read the documentation for more details on HPy motivation, goals, and features, for example:

  • debug mode for better developer experience
  • support for incremental porting from CPython API to HPy
  • CPython ABI for raw performance on CPython
  • and others

Do you want to see how HPy API looks in code? Check out our quickstart example.

You may also be interested in HPy's API reference.

This repository contains the API and ABI specification and implementation for the CPython interpreter. Other interpreters that support HPy natively: GraalPy and PyPy, provide their own builtin HPy implementations.

Why should I care about this stuff?

  • the existing C API is becoming a problem for CPython and for the evolution of the language itself: this project makes it possible to make experiments which might be "officially" adopted in the future

  • for PyPy, it will give obvious speed benefits: for example, data scientists will be able to get the benefit of fast C libraries and fast Python code at the same time, something which is hard to achieve now

  • the current implementation is too tied to CPython and proved to be a problem for almost all the other alternative implementations. Having an API which is designed to work well on two different implementations will make the job much easier for future ones: going from 2 to N is much easier than going from 1 to 2

  • arguably, it will be easier to learn and understand than the massive CPython C API

See also Python Performance: Past, Present, Future by Victor Stinner.

What does HPy mean?

The "H" in HPy stands for "handle": one of the key idea of the new API is to use fully opaque handles to represent and pass around Python objects.

Donate to HPy

Become a financial contributor and help us sustain the HPy community: Contribute to HPy.

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

hpy-0.9.0rc1.tar.gz (348.8 kB view hashes)

Uploaded Source

Built Distributions

hpy-0.9.0rc1-cp311-cp311-musllinux_1_1_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

hpy-0.9.0rc1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

hpy-0.9.0rc1-cp311-cp311-macosx_10_9_x86_64.whl (570.9 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

hpy-0.9.0rc1-cp310-cp310-musllinux_1_1_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

hpy-0.9.0rc1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

hpy-0.9.0rc1-cp310-cp310-macosx_10_9_x86_64.whl (572.9 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

hpy-0.9.0rc1-cp39-cp39-musllinux_1_1_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

hpy-0.9.0rc1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

hpy-0.9.0rc1-cp39-cp39-macosx_10_9_x86_64.whl (569.8 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

hpy-0.9.0rc1-cp38-cp38-musllinux_1_1_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

hpy-0.9.0rc1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

hpy-0.9.0rc1-cp38-cp38-macosx_10_9_x86_64.whl (580.0 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ 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