Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

An implementation of the Entity-Component-System pattern.

Project description


An implementation of the Entity-Component-System pattern.

PyPI PyPI - Status PyPI - Python Version PyPI - License

Build Status Code style: black Checked with mypy


This project is available on PyPI so you can simply install it via

pip install pyecs


from dataclasses import dataclass
from typing import Tuple

from pyecs import ECSController, Component, preconfigure_system, register_system

# 1. build your components
class Transform(Component, identifier="transform"):
    position: Tuple[float, float] = (0.0, 0.0)

class Rigidbody(Component, identifier="rigidbody"):
    velocity: Tuple[float, float] = (0.0, 0.0)
    acceleration: Tuple[float, float] = (0.0, 0.0)

# 2. define some systems
@preconfigure_system((Transform, Rigidbody))
def physics(delta_t, data, entities):
    for entity in entities:
        entity.rigidbody.velocity = (
            entity.rigidbody.velocity[0] + entity.rigidbody.acceleration[0] * delta_t,
            entity.rigidbody.velocity[1] + entity.rigidbody.acceleration[1] * delta_t,
        entity.transform.position = (
            entity.transform.position[0] + entity.rigidbody.velocity[0] * delta_t,
            entity.transform.position[1] + entity.rigidbody.velocity[1] * delta_t,

def introspect_position(delta_t, data, entities):
    for entity in entities:
        print(f"Entity {entity.uuid}: position = {entity.transform.position}")

if __name__ == "__main__":
    # 3. setup controller
    controller = ECSController()
    register_system(controller, physics)
    register_system(controller, introspect_position)

    # 4. add some entities
        Transform(), Rigidbody(acceleration=(1.0, 0.0))
        Transform(), Rigidbody(acceleration=(0.0, 1.0))
        Transform(), Rigidbody(acceleration=(1.0, 1.0))

    # 5. run everything

Dev Setup

Simply install pipenv and run the following line:

pipenv install --dev

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pyecs, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size pyecs-0.2-py2.py3-none-any.whl (8.4 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size pyecs-0.2.tar.gz (8.1 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page