Python Bindings for Box2D v3 using CFFI
Python bindings for the Box2D physics engine version 3. Provides Pythonic access to Box2D's feature set.
Install from source using pip
pip install "git+https://github.com/giorgosg/box2d-py.git"To include the testbed:
pip install "box2d-python[testbed] @ git+https://github.com/giorgosg/box2d-py.git"Or Install from pypi:
pip install box2d-python[testbed]box2d-testbedfrom box2d import World, Vec2
# Create physics world
world = World(gravity=(0, -9.81))
# Create static ground body
ground = world.new_body().static().position((0, -5)).box(1, 10).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(60):
world.step(1/60, 4)
Currently supports some of the Box2D v3.0 functionality with active development ongoing.