Skip to main content

Pymunk is a easy-to-use pythonic 2D physics library

Project description

https://raw.githubusercontent.com/viblo/pymunk/master/docs/src/_static/pymunk_logo_animation.gif

Pymunk is an easy-to-use pythonic 2D physics library that can be used whenever you need 2D rigid body physics from Python. Perfect when you need 2D physics in your game, demo or simulation! It is built on top of the very capable 2D physics library Chipmunk2D.

The first version was released in 2007 and Pymunk is still actively developed and maintained today, more than 15 years of active development!

Pymunk has been used with success in many projects, big and small. For example: 3 Pyweek game competition winners, dozens of published scientific papers and even in a self-driving car simulation! See the Showcases section on the Pymunk webpage for some examples.

2007 - 2024, Victor Blomqvist - vb@viblo.se, MIT License

This release is based on the latest Pymunk release (6.9.0), using Chipmunk2D 7 rev dfc2fb8ca023ce6376fa2cf4a7f91c92ee08a970.

Installation

In the normal case Pymunk can be installed from PyPI with pip:

> pip install pymunk

It has one direct dependency, CFFI.

Pymunk can also be installed with conda, from the conda-forge channel:

> conda install -c conda-forge pymunk

For more detailed installation instructions, please see the complete Pymunk documentation.

Example

Quick code example:

import pymunk               # Import pymunk..

space = pymunk.Space()      # Create a Space which contain the simulation
space.gravity = 0,-981      # Set its gravity

body = pymunk.Body()        # Create a Body
body.position = 50,100      # Set the position of the body

poly = pymunk.Poly.create_box(body) # Create a box shape and attach to body
poly.mass = 10              # Set the mass on the shape
space.add(body, poly)       # Add both body and shape to the simulation

print_options = pymunk.SpaceDebugDrawOptions() # For easy printing

for _ in range(100):        # Run simulation 100 steps in total
    space.step(0.02)        # Step the simulation one step forward
    space.debug_draw(print_options) # Print the state of the simulation

This will print (to console) the state of the simulation. For more visual, detailed and advanced examples, take a look at the included demos. They are included in the Pymunk install, in the pymunk.examples subpackage. They can be run directly. To list the examples:

> python -m pymunk.examples -l

And to run one of them:

> python -m pymunk.examples.breakout

Contact & Support

Homepage

http://www.pymunk.org/

Stackoverflow

You can ask questions/browse old ones at Stackoverflow, just look for the Pymunk tag. http://stackoverflow.com/questions/tagged/pymunk

E-Mail

You can email me directly at vb@viblo.se

Issue Tracker

Please use the issue tracker at Github to report any issues you find. This is also the place for feature requests: https://github.com/viblo/pymunk/issues

Regardless of the method you use I will try to answer your questions as soon as I see them. (And if you ask on Stackoverflow other people might help as well!)

Documentation

The full documentation including API reference, showcase of usages and screenshots of examples is available on the Pymunk homepage, http://www.pymunk.org

The Pymunk Vision

Make 2D physics easy to include in your game

It is (or is striving to be):

  • Easy to use - It should be easy to use, no complicated code should be needed to add physics to your game or program.

  • “Pythonic” - It should not be visible that a c-library (Chipmunk) is in the bottom, it should feel like a Python library (no strange naming, OO, no memory handling and more)

  • Simple to build & install - You shouldn’t need to have a zillion of libraries installed to make it install, or do a lot of command line tricks.

  • Multi-platform - Should work on both Windows, *nix and OSX.

  • Non-intrusive - It should not put restrictions on how you structure your program and not force you to use a special game loop, it should be possible to use with other libraries like Pygame and Pyglet.

Dependencies / Requirements

Basically Pymunk have been made to be as easy to install and distribute as possible, usually pip install will take care of everything for you.

  • Python (Runs on CPython 3.8 and later and Pypy3)

  • Chipmunk (Prebuilt and included when using binary wheels)

  • CFFI (will be installed automatically by Pip)

  • Setuptools (should be included with Pip)

  • GCC and friends (optional, you need it to compile Pymunk from source. On windows Visual Studio is required to compile)

  • Pygame (optional, you need it to run the Pygame based demos)

  • Pyglet (optional, you need it to run the Pyglet based demos)

  • Matplotlib & Jupyter Notebook (optional, you need it to run the Matplotlib based demos)

  • Numpy (optional, you need to it run a few demos)

  • Sphinx & aafigure & sphinx_autodoc_typehints (optional, you need it to build documentation)

Older Pythons

  • Support for Python 2 (and Python 3.0 - 3.5) was dropped with Pymunk 6.0.

  • Support for Python 3.6 was dropped with Pymunk 6.5.2.

  • Support for Python 3.7 was dropped with Pymunk 6.8.2

If you use any of these legacy versions of Python, please use an older Pymunk version. (It might work on newer Pymunks as well, but it’s not tested, and no wheels are built.)

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

pymunk-6.9.0.tar.gz (3.1 MB view hashes)

Uploaded Source

Built Distributions

pymunk-6.9.0-cp313-cp313-win_amd64.whl (366.7 kB view hashes)

Uploaded CPython 3.13 Windows x86-64

pymunk-6.9.0-cp313-cp313-win32.whl (315.3 kB view hashes)

Uploaded CPython 3.13 Windows x86

pymunk-6.9.0-cp313-cp313-musllinux_1_2_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.13 musllinux: musl 1.2+ x86-64

pymunk-6.9.0-cp313-cp313-musllinux_1_2_i686.whl (976.3 kB view hashes)

Uploaded CPython 3.13 musllinux: musl 1.2+ i686

pymunk-6.9.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

pymunk-6.9.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (990.4 kB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pymunk-6.9.0-cp313-cp313-macosx_11_0_arm64.whl (347.1 kB view hashes)

Uploaded CPython 3.13 macOS 11.0+ ARM64

pymunk-6.9.0-cp313-cp313-macosx_10_13_x86_64.whl (364.7 kB view hashes)

Uploaded CPython 3.13 macOS 10.13+ x86-64

pymunk-6.9.0-cp312-cp312-win_amd64.whl (366.7 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

pymunk-6.9.0-cp312-cp312-win32.whl (315.3 kB view hashes)

Uploaded CPython 3.12 Windows x86

pymunk-6.9.0-cp312-cp312-musllinux_1_2_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

pymunk-6.9.0-cp312-cp312-musllinux_1_2_i686.whl (976.3 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

pymunk-6.9.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pymunk-6.9.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (990.4 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pymunk-6.9.0-cp312-cp312-macosx_11_0_arm64.whl (347.1 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

pymunk-6.9.0-cp312-cp312-macosx_10_13_x86_64.whl (364.7 kB view hashes)

Uploaded CPython 3.12 macOS 10.13+ x86-64

pymunk-6.9.0-cp311-cp311-win_amd64.whl (366.7 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

pymunk-6.9.0-cp311-cp311-win32.whl (315.3 kB view hashes)

Uploaded CPython 3.11 Windows x86

pymunk-6.9.0-cp311-cp311-musllinux_1_2_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

pymunk-6.9.0-cp311-cp311-musllinux_1_2_i686.whl (975.0 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

pymunk-6.9.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pymunk-6.9.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (988.6 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pymunk-6.9.0-cp311-cp311-macosx_11_0_arm64.whl (346.9 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pymunk-6.9.0-cp311-cp311-macosx_10_9_x86_64.whl (364.3 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pymunk-6.9.0-cp310-cp310-win_amd64.whl (366.7 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pymunk-6.9.0-cp310-cp310-win32.whl (315.3 kB view hashes)

Uploaded CPython 3.10 Windows x86

pymunk-6.9.0-cp310-cp310-musllinux_1_2_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

pymunk-6.9.0-cp310-cp310-musllinux_1_2_i686.whl (975.0 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

pymunk-6.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pymunk-6.9.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (988.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pymunk-6.9.0-cp310-cp310-macosx_11_0_arm64.whl (346.9 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pymunk-6.9.0-cp310-cp310-macosx_10_9_x86_64.whl (364.3 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pymunk-6.9.0-cp39-cp39-win_amd64.whl (366.7 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pymunk-6.9.0-cp39-cp39-win32.whl (315.3 kB view hashes)

Uploaded CPython 3.9 Windows x86

pymunk-6.9.0-cp39-cp39-musllinux_1_2_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

pymunk-6.9.0-cp39-cp39-musllinux_1_2_i686.whl (974.9 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ i686

pymunk-6.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pymunk-6.9.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (988.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pymunk-6.9.0-cp39-cp39-macosx_11_0_arm64.whl (346.9 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pymunk-6.9.0-cp39-cp39-macosx_10_9_x86_64.whl (364.3 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pymunk-6.9.0-cp38-cp38-win_amd64.whl (366.7 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

pymunk-6.9.0-cp38-cp38-win32.whl (314.8 kB view hashes)

Uploaded CPython 3.8 Windows x86

pymunk-6.9.0-cp38-cp38-musllinux_1_2_x86_64.whl (1.0 MB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.2+ x86-64

pymunk-6.9.0-cp38-cp38-musllinux_1_2_i686.whl (975.1 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.2+ i686

pymunk-6.9.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pymunk-6.9.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (988.8 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ i686 manylinux: glibc 2.5+ i686

pymunk-6.9.0-cp38-cp38-macosx_11_0_arm64.whl (347.0 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

pymunk-6.9.0-cp38-cp38-macosx_10_9_x86_64.whl (364.3 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