pydamics
A small, chainable-syntax 2D physics engine for Python. 3D support planned.
Install
pip install pydamics # once published to PyPI
# or, from source:
pip install -e .
Usage
from pydamics import Entity, World
ball = Entity(mass=2.0, position=(0, 10))
ball.physics2d.gravity(force=9.8)
ball.physics2d.fluid(density=1.2, drag=0.3)
world = World()
world.add(ball)
# Option 1: step it yourself
for _ in range(120):
world.step(dt=1/60)
print(ball.position)
# Option 2: let the engine run itself on a background thread
world.run(dt=1/60)
...
world.stop()
Attachable forces (entity.physics2d)
| Method | Description |
|---|---|
.gravity(force=9.8, direction=None) |
Constant acceleration in a direction (default: down) |
.fluid(density=1.0, drag=0.1) |
Velocity-proportional drag (air/water resistance) |
.friction(coefficient=0.3, normal_force=9.8) |
Kinetic friction opposing motion |
.custom(force) |
Attach your own Force subclass |
.remove(force) |
Detach a previously attached force |
.clear() |
Detach all forces |
Every attach method returns the Force object, so you can hold onto it and
remove/tweak it later:
g = ball.physics2d.gravity(force=9.8)
ball.physics2d.remove(g)
Integration
Uses Velocity Verlet integration (not simple Euler, not full RK4) — it's the standard for force-based particle sims: stable, and integrates naturally with drag and future collision impulses.
Tests
pip install -e ".[dev]"
pytest tests/
Visual demos
Install the extra deps first:
pip install -e ".[visual]"
Matplotlib (headless, renders a GIF) -- great for servers, CI, or just sharing a result without needing a display:
python examples/visual_matplotlib.py
# -> saves examples/falling_balls.gif
Pygame (interactive window) -- click anywhere to drop a new ball, watch gravity/drag/floor-bounces play out live:
python examples/visual_pygame.py
# click to drop balls, ESC or close window to quit
Note: the floor-bounce behavior in both demos is demo-level logic (a
simple world.on_step hook), not part of the core engine yet -- proper
collision detection/response is still on the roadmap below.
Roadmap
- Collision detection/response
- More force types (springs, wind, etc.)
- 3D physics namespace (
entity.physics3d)
Publishing (for maintainers)
1. Push to GitHub
git init
git add .
git commit -m "Initial commit: pydamics 2D physics engine"
git branch -M main
git remote add origin https://github.com/<your-username>/pydamics.git
git push -u origin main
The .github/workflows/tests.yml workflow will auto-run the test suite on
every push.
2. One-time PyPI setup (Trusted Publishing — no API tokens needed)
- Create a PyPI account if you don't have one.
- Go to pypi.org → Your account → Publishing and add a new "trusted publisher":
- PyPI project name:
pydamics - Owner:
<your-github-username> - Repository name:
pydamics - Workflow name:
publish.yml - Environment name:
pypi
- PyPI project name:
- In your GitHub repo, go to Settings → Environments and create an environment named
pypi(this matches the workflow file — no secrets needed, trusted publishing handles auth).
3. Ship a release
Bump the version in pyproject.toml, commit, then on GitHub:
Releases → Draft a new release → tag v0.1.0 → Publish release.
That triggers .github/workflows/publish.yml, which builds the package and
uploads it to PyPI automatically. From then on, anyone can:
pip install pydamics
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydamics-0.1.1.tar.gz.
File metadata
- Download URL: pydamics-0.1.1.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
153293c037073df4abe924f289f818ba8bd6997642aa457e125ba0bd286768fe
|
|
| MD5 |
85117248726815aa07a2000cb47b841d
|
|
| BLAKE2b-256 |
27a149474136aaa5e29e1edb76acd7cfbb82b75124b4929f8d21975c25c7459e
|
Provenance
The following attestation bundles were made for pydamics-0.1.1.tar.gz:
Publisher:
publish.yml on Reeed-cell/Pydamics
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydamics-0.1.1.tar.gz -
Subject digest:
153293c037073df4abe924f289f818ba8bd6997642aa457e125ba0bd286768fe - Sigstore transparency entry: 2280805622
- Sigstore integration time:
-
Permalink:
Reeed-cell/Pydamics@3d31c52a4a98b406b29b4b3008b3180b38ca6391 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Reeed-cell
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3d31c52a4a98b406b29b4b3008b3180b38ca6391 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pydamics-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pydamics-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe8043abb866e8ada28860ece06797e466f009b64e250b21d8f4984df40e793c
|
|
| MD5 |
0832a74c9f3576378a41eb7cf38da03d
|
|
| BLAKE2b-256 |
99ec3c024a5bdcbedfe730d87102885df413e9fc4f072a996527294c6203dd8f
|
Provenance
The following attestation bundles were made for pydamics-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on Reeed-cell/Pydamics
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pydamics-0.1.1-py3-none-any.whl -
Subject digest:
fe8043abb866e8ada28860ece06797e466f009b64e250b21d8f4984df40e793c - Sigstore transparency entry: 2280805649
- Sigstore integration time:
-
Permalink:
Reeed-cell/Pydamics@3d31c52a4a98b406b29b4b3008b3180b38ca6391 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/Reeed-cell
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3d31c52a4a98b406b29b4b3008b3180b38ca6391 -
Trigger Event:
release
-
Statement type: