PyECS Documentation#
PyECS is a Python Entity Component System (ECS) implementation with runtime type safety powered by beartype.
Features#
Type-safe - Leverages beartype for runtime type checking
Pure Python - No external dependencies except beartype
Fast - Archetype-based storage for efficient component queries
Simple - Clean, Pythonic API that’s easy to understand
Installation#
pip install pyecs
Quick Start#
from dataclasses import dataclass
from pyecs import ECSWorld
from pyecs.querying.Query import Query
@dataclass
class Position:
x: float = 0
y: float = 0
@dataclass
class Velocity:
x: float = 0
y: float = 0
class MovementSystem:
def update(self, world, dt):
query = Query().with_components(Position, Velocity)
entities = query.execute(world)
for entity in entities:
pos = world.get_component(entity, Position)
vel = world.get_component(entity, Velocity)
pos.x += vel.x * dt
pos.y += vel.y * dt
world = ECSWorld()
world.add_system(MovementSystem())
entity = world.create_entity()
world.add_component(entity, Position(x=0, y=0))
world.add_component(entity, Velocity(x=1, y=0))
world.update(dt=1.0)