This release is a pre-release and may not be stable for production use.
box2d-py
Python bindings for the Box2D physics engine v3.2.0, built with CFFI. Box2D itself is compiled into the package and does the simulating; the bodies, shapes, joints, queries and events around it are ordinary Python objects. It runs on Linux, macOS and Windows with Python 3.12, 3.13 or 3.14, and in WebAssembly under Pyodide. A testbed comes with it: a window of example scenarios to run and edit, and to write your own in.
Installation
pip install --pre box2d-python
The testbed is the testbed extra:
pip install --pre "box2d-python[testbed]"
--pre is there while the release is a candidate, 3.2.0rc1. Wheels are built
for Linux, macOS and Windows, so nothing is compiled. The current main
installs from git instead, building Box2D from source with git, a C compiler
and CMake 3.22 or newer:
pip install "box2d-python[testbed] @ git+https://github.com/giorgosg/box2d-py.git"
The 0.1.x releases on PyPI predate the Box2D v3.2 port and have a different API. What changes between releases is in CHANGELOG.md. Installation in the documentation has the rest: building from a clone, and how the versions are numbered.
Example usage
from box2d import World
# Create physics world
world = World(gravity=(0, -9.81))
# Create static ground body (box takes full width and height)
ground = world.new_body().static().position(0, -5).box(20, 1).build()
# Create dynamic bodies
bodybuilder = world.new_body().dynamic().box(0.5, 0.5)
bodies = [bodybuilder.position(x, 5).build() for x in range(-5, 5)]
# Simulation loop
for _ in range(180):
world.step(1 / 60, 4)
# Bodies have come to rest on top of the ground
print(round(bodies[0].position.y, 2)) # -4.25
Box2D checks what it is given. An argument it rejects raises
box2d.InvalidInputError, a ValueError, from the call that passed it --
naming the Box2D function and the check that failed -- and leaves the world as
it was:
>>> body = world.new_body().dynamic().build()
>>> body.add_circle(radius=0.5, density=-1)
Traceback (most recent call last):
...
box2d.InvalidInputError: b2CreateCircleShape rejected its input: b2IsValidFloat( def->density ) && def->density >= 0.0f (in b2CreateShape)
Box2D's other diagnostics, such as a body going unstable, are logged to the
box2d logger.
The quickstart builds a first scene step by step, and the documentation covers the rest of the API.
The testbed
box2d-testbed
A window of scenarios, each showing one part of Box2D running live, with its
own controls in the side panel. p pauses, o steps, r resets the
scenario, Home resets the view, and [ ] move between scenarios. Drag a
body with the left button to pull it, drag with the middle button to pan, and
scroll to zoom.
Running the testbed covers the panels, the settings
and the rest.
What a scenario looks like
A scenario is a class, and declaring it registers it under the category and name it gives:
from box2d_testbed.base_test import BaseTest, UI
class Drop(BaseTest, category="Bodies", name="Drop"):
"""A box dropped onto the ground from a height you choose.
Watch it settle: Box2D puts a body to sleep once it has been still for a
moment, and the status line says when that happens.
"""
camera_center = (0, 5)
camera_zoom = 12.0
drop_height = UI.float(8.0, min=1.0, max=20.0)
def setup(self):
self.world.new_body().static().segment((-20, 0), (20, 0)).build()
self.box = (
self.world.new_body()
.dynamic()
.position(0, self.drop_height)
.box(1, 1, friction=0.4)
.build()
)
@drop_height.callback
def on_drop_height(self, key, value):
# Where the box starts is part of building the scene, so build it again.
self.rebuild()
def status(self):
return "asleep" if not self.box.awake else f"height {self.box.position.y:.1f}"
setup builds the scene, the UI declarations are controls in its panel, and
status is shown at the top left of the view. Your own scenarios are Python
files in a directory of your own, which the Editor tab, beside the
simulation, edits: Ctrl+S saves the file, runs it, and puts its scenario on
screen, with nothing restarted. Fork copies any scenario, the shipped
ones included, into a file of your own to change. A scenario that raises, while
building or from any of its methods or controls, has the traceback shown in its
panel rather than closing the window.
Writing scenarios covers all of it.
The console
The Console panel along the bottom is a Python prompt on the running
simulation, with test and world bound to what is running, and completion
on the live objects. The console covers it.
Running in a browser
The testbed also runs in a web page: CPython, Box2D and the bindings compiled
to WebAssembly with Pyodide. It is single threaded, and what you write in its
editor lasts until the page reloads, unless you share it: Share uploads a
scenario and copies its public link, and Open link opens one read-only,
without running it until you press Run.
The testbed in a browser covers the differences, and
web/README.md
building and serving it.
Development status
3.2.0rc1 is the first release of these bindings for Box2D v3.2, and a release candidate: the API may still change before 3.2.0.
Built against Box2D's v3.2.0 release (box2d.BOX2D_VERSION); the box2d
submodule is pinned to that tag. The binding's own version is
box2d.__version__.
Bound and covered by tests on Linux, macOS and Windows for Python 3.12, 3.13 and 3.14, and in WebAssembly:
- bodies, every shape, and chains
- every joint type -- distance, filter, motor, mover, pogo, prismatic, revolute, weld and wheel -- plus a mouse joint for dragging
- sensor, contact, hit, body-move and joint events, and the pre-solve, pre-continuous, custom filter and material mixing callbacks
- the collision queries and casts
- character movement, both kinematic (the mover queries and plane solver) and dynamic (the mover and pogo joints)
- solver tuning, profiling counters and a deterministic state hash
Not bound yet: world snapshots, and recording and replay.
CONTRIBUTING.md covers building from source, the tests and the project's conventions.
Links
Metadata
Release files for box2d-python 3.2.0rc1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| box2d_python-3.2.0rc1.tar.gz | 1.7 MB | With provenance | Details for box2d_python-3.2.0rc1.tar.gz |
Built distributions (wheels)
Total release size: 6.9 MB
Release files / box2d_python-3.2.0rc1.tar.gz
| Download URL | box2d_python-3.2.0rc1.tar.gz |
|---|---|
| Size | 1.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a9e1063f62532d2dac809c5713c3521b13377e5c822e56501d89425e2a3aec8c
|
|
BLAKE2b-256 checksum How to use checksums |
e85eff7dcf707be7a7a2719217d1c255a98d93cb17dcd0aced65b9cda2135dab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / box2d_python-3.2.0rc1-cp312-abi3-win_amd64.whl
| Download URL | box2d_python-3.2.0rc1-cp312-abi3-win_amd64.whl |
|---|---|
| Size | 579.1 kB |
| Tags | CPython 3.12 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
2a29a719b6316551c9e3513d5df1d04c19980e2e7157635fbc398f879aefe09d
|
|
BLAKE2b-256 checksum How to use checksums |
43de748a6c856ead8de34946a66b1aebe40b2555f076ce1dd77fd4d172410152
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / box2d_python-3.2.0rc1-cp312-abi3-musllinux_1_2_x86_64.whl
| Download URL | box2d_python-3.2.0rc1-cp312-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 880.8 kB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
c72cbe2cea6054d74a25b3f2e916ab70f88d908669c0ec5b420c73ef47f1efdf
|
|
BLAKE2b-256 checksum How to use checksums |
9a9ecdfff6e389095eb18deda771af3aecc77cb4f73fadc994a1329d450dddb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / box2d_python-3.2.0rc1-cp312-abi3-musllinux_1_2_aarch64.whl
| Download URL | box2d_python-3.2.0rc1-cp312-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 869.2 kB |
| Tags | CPython 3.12 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
6911931c734698998f1f81c54b759265b0dc5c56bf0564178d2bd4c4d69a9134
|
|
BLAKE2b-256 checksum How to use checksums |
a847a9bb139164f5c53f691886bd0145ab21988349d25cdcb0d3d45e18d96ea9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / box2d_python-3.2.0rc1-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
| Download URL | box2d_python-3.2.0rc1-cp312-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 872.3 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
1d84d95a7877e8961d1bc203e944f091acd23fe4f6e862beb47c8a5e6251c787
|
|
BLAKE2b-256 checksum How to use checksums |
c9a791d444e06773106b84489c6f561679d5167802f0df8e60db02a15edd4b52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / box2d_python-3.2.0rc1-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
| Download URL | box2d_python-3.2.0rc1-cp312-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 853.4 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
332c473c744b92906eebfdc2bb7367d40616f99e41a75d767aba99dc53555cd1
|
|
BLAKE2b-256 checksum How to use checksums |
93f2ce3f9cc6bd5d9a8f8b6599f1f996c5c621cda94ec4d1eb51ecb819d51bd7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / box2d_python-3.2.0rc1-cp312-abi3-macosx_11_0_arm64.whl
| Download URL | box2d_python-3.2.0rc1-cp312-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 547.4 kB |
| Tags | CPython 3.12 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
d320dc25db549d90a0bd496f5adc34489d921ef5f866641d2827954932f5d883
|
|
BLAKE2b-256 checksum How to use checksums |
c82ea3c71349533faba966c98da44683e54d5908d56150cedca942960b910676
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / box2d_python-3.2.0rc1-cp312-abi3-macosx_10_13_x86_64.whl
| Download URL | box2d_python-3.2.0rc1-cp312-abi3-macosx_10_13_x86_64.whl |
|---|---|
| Size | 570.0 kB |
| Tags | CPython 3.12 abi3 macOS 10.13+ x86-64 |
|
SHA-256 checksum How to use checksums |
65b6493fd6b320fd2df1f6a3dd028d3c94fb55be33360ab8772e44d2edf8f6dc
|
|
BLAKE2b-256 checksum How to use checksums |
f857adcd16a3290d0f3d453fe9583c1deeac1e25f9d3c7a5c79635f8c6a18792
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logSecurity for box2d-python 3.2.0rc1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 8 files in this release have been uploaded with provenance metadata.
Attestation for box2d_python-3.2.0rc1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.