Skip to main content

MicroECS

Minimal (~850 LoC) Entity Component System in python and numpy. Examples also use raylib for rendering.

Usage:

  • Via pip: pip install microecs
  • From source code:
git clone https://gitlab.com/meehai/microecs      # clone the source code
cd microecs                                       # go in the cloned directory
python -m venv .venv && source .venv/bin/activate # make a virtual env, optional but useful
python -m pip install -e .                        # install micro ecs in this virtual env
python -m pytest test/                            # run the unit & integration tests to verify installation
python examples/01-hello-world.py                 # run the basic hello world example (others in that dir)

Docs: meehai.gitlab.io/microecs

Simple example

from dataclasses import field
import numpy as np
from microecs import World, Component

class HasPosition(Component):
    position: np.ndarray = field(metadata={"shape": (2, ), "dtype": "float32", "default": np.float32([0, 0])})
class HasVelocity(Component):
    velocity: np.ndarray = field(metadata={"shape": (2, ), "dtype": "float32", "default": np.float32([0, 0])})

world = World(components=[HasPosition, HasVelocity])
# both velocity and position (data) are optional since they have a default
eid1 = world.add_entity(components=[HasPosition, HasVelocity])
# data is passed as kwargs to add_entity
eid2 = world.add_entity(components=[HasPosition, HasVelocity],
                        velocity=np.float32([1, 1]))
world.update() # add_entity uses a command buffer internally until this is called
print(f"Added 2 entities. Id1={eid1}, Id2={eid2}")

# Querying: batch operate on all entities at once.
qr = world.query(HasVelocity) # qr is a QueryResult object, a numpy-based Structure of Arrays (SoA).
qr.velocity += np.float32([0.1, 0.5])

Documentation

  • Primitives — the five building blocks (Component, Entity, Pool, QueryResult, World), mutation timing, and how numpy-like the query views really are.
  • Systems & Per-Entity Iteration — writing systems, the three ways to touch data (vectorized, zip-rows, the Entity API), and when each is right.
  • Hello World (raylib) — a complete runnable program, walked through part by part.
  • Benchmarks — microecs vs OOP, and microecs vs six other Python ECS libraries (including the C++ EnTT and C flecs bindings) across seven workloads and an N-sweep to 1M.

Download files

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

Source Distribution

microecs-0.8.1.tar.gz (16.8 kB view details)

Uploaded Source

File details

Details for the file microecs-0.8.1.tar.gz.

File metadata

  • Download URL: microecs-0.8.1.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for microecs-0.8.1.tar.gz
Algorithm Hash digest
SHA256 a7dca529b3741941ea0d9a3d1ba6ea66a3f925c363c83ef0907515c8bd6d3fa5
MD5 78fb4ad9d78dc098662c84095f7fa271
BLAKE2b-256 49fad2565bdf1a04cf2c2a6e69b87d441344e56544c06aee96d6f832066df5f5

See more details on using hashes here.

Release history Release notifications | RSS feed

0.8.3

1 file

0.8.2

1 file

This release

0.8.1 This release

1 file

0.8.0

1 file

0.7.0

1 file

0.6.1

1 file

0.6.0

1 file

0.5.1

1 file

0.5.0

1 file

0.4.6

1 file

0.4.5

1 file

0.4.4

1 file

0.4.3

1 file

0.4.2

1 file

0.4.1

1 file

0.4.0

1 file

0.3.9

1 file

0.3.8

1 file

0.3.7

1 file

0.3.6

1 file

0.3.4

1 file

0.3.3

1 file

0.3.2

1 file

0.3.1

1 file

0.3.0

1 file

0.2.4

1 file

0.2.3

1 file

0.2.2

1 file

0.2.1

1 file

0.2.0

1 file

0.1.1

1 file

0.1.0

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page