Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Repository files navigation

pyecs

A simple implementation of the Entity-Component pattern.

PyPI - VersionPyPI - StatusPyPI - Python VersionPyPI - License

Build Statuscodecovcodebeat badgeCode style: blackChecked with mypy

Install

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

pip install pyecs

Example

fromdataclassesimportdataclassfromtypingimportTuplefrompyecsimportStore# 1. build your components@dataclassclassTransform:
position: Tuple[float, float] = (0.0, 0.0)
@dataclassclassRigidbody:
velocity: Tuple[float, float] = (0.0, 0.0)
acceleration: Tuple[float, float] = (0.0, 0.0)
if__name__=="__main__":
# 2. intialize entity-component storestore=Store()
# 3. add some entitiesscene=store.add_entity()
scene.add_child(Transform(), Rigidbody(acceleration=(1.0, 0.0)))
scene.add_child(Transform(), Rigidbody(acceleration=(0.0, 1.0)))
scene.add_child(Transform(), Rigidbody(acceleration=(1.0, 1.0)))
# 4. run everythingwhileTrue:
forentityinstore.get_entities_with(Transform, Rigidbody):
transform, rigidbody=entity.get_components(Transform, Rigidbody)
rigidbody.velocity= (
rigidbody.velocity[0] +rigidbody.acceleration[0],
rigidbody.velocity[1] +rigidbody.acceleration[1],
)
transform.position= (
transform.position[0] +rigidbody.velocity[0],
transform.position[1] +rigidbody.velocity[1],
)
print(f"{transform=}\t{rigidbody=}")

Dev Setup

Simply install pipenv and run the following line:

pipenv install --dev

About

An implementation of the Entity-Component-System pattern.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages