Skip to main content

ecs-cub

A high-performance Entity Component System with a C++23 core and Python bindings via pybind11.

⚠️ Research project — not production ready. We're exploring, not shipping.


Features

  • Entities — lightweight integer IDs with freelist reuse and optional generation-checked Entity handles
  • Components — any Python object, indexed by its exact type
  • Queries — reusable query signatures, exclusion filters (Exclude(Dead)), and NOT_ANY(A, B, C) NOR semantics
  • Systems — push model (ECS calls your update()) or pull model (you ask for results when you want them); opt out of entity IDs when you don't need them
  • Tags — unique 1:1 string → entity mapping, O(1) lookup
  • Groups — 1:many grouping, entities can belong to multiple groups simultaneously
  • Events — signals (1:1 handler) and pub/sub (1:many subscribers); internal lifecycle events auto-published for entity/component changes
  • Resources — Python-owned registry resources plus explicitly process-wide resources
  • Deferred kills — kill_entity() is deferred by default to prevent iterator invalidation during system updates
  • Marker components — filter by presence without passing the component into results, saving allocations per entity

Performance

  • 65MB memory for 1,000,000 entities
  • O(1) entity creation, component add/remove, tag and group lookups
  • 32-bit bitmask signatures for fast system matching
  • Sparse sets for component storage

Features

Entities

from ecs_cub.api import Health, Inventory, Position, Velocity, create_entity, create_entity_obj

# Lightweight integer IDs
entity_id = create_entity(Position(0, 0), Velocity(1, 0))

# Or a generation-checked wrapper that cannot alias a recycled entity ID
player = create_entity_obj(Position(0, 0), Health(100))
player.tag("player")
player.add_component(Inventory())
player.kill()

IDs are reused via a freelist (LIFO). Max 1,048,576 entities by default, configurable at compile time.


Components

from fond import struct

@struct(slots=True)
class Position:
    x: float
    y: float

Components are identified by their exact Python type. They can be ordinary classes, slotted dataclasses, Fond Struct records, or any other Python object; no ECS base class or metaclass is required.


Queries

from ecs_cub.api import Exclude, create_query, get_components

query = create_query(Position, Velocity)
for entity_id, (pos, vel) in get_components(query):
    pos.x += vel.dx

# Exclusion — entities with Position but NOT Dead
query = create_query(Position, Exclude(Dead))

Systems

Two patterns, pick what fits:

# Push model — ECS calls update() for you
class MovementSystem(SystemBase):
    required_components = (Position, Velocity)

    def update(self, results, dt):
        for entity_id, (pos, vel) in results:
            pos.x += vel.dx * dt

# Pull model — you ask for results when you want them
sys_idx = register_system(Position, Velocity)
results = get_system_results(sys_idx)

Skip entity IDs when you don't need them:

class DecaySystem(SystemBase):
    required_components = (Health,)
    include_entity_id = False  # Skips Py_INCREF per entity — faster

Tags & Groups

# Tags — 1:1 unique mapping
tag_entity(entity_id, "player")
player_id = get_entity_by_tag("player")

# Groups — 1:many, entities can belong to multiple groups
group_entity(entity_id, "enemies")
group_entity(entity_id, "bosses")  # same entity, two groups
enemies = get_entities_by_group("enemies")

Events & Pub/Sub

# Signals — 1:1 handler
connect("player_died", on_player_death)
fire("player_died", player_id)

# Pub/Sub — 1:many subscribers
subscribe("damage_dealt", log_damage)
subscribe("damage_dealt", update_ui)
publish("damage_dealt", entity_id, amount)

Internal lifecycle events are auto-published on _entity:created, _entity:killed, _component:added, and _component:removed.


Resources

Resources are indexed by their exact Python type. Registry-scoped resources stay in Python, so ordinary access does not cross the C++ boundary.

from fond import struct

from ecs_cub.api import get_local_resource, set_resource


@struct(slots=True)
class FrameClock:
    delta_time: float = 0.0


clock = FrameClock(delta_time=0.016)
set_resource(clock)

# Lookups return MaybeIDK; value() raises when the resource is absent.
dt = get_local_resource(FrameClock).value().delta_time

There is one resource slot per exact type, so setting another FrameClock replaces the existing value. Passing a class instead of an instance default-constructs it with no arguments.

Process-wide resources survive clear_database() for things like input state or configuration:

from ecs_cub.api import get_global_resource, set_global_resource


@struct(slots=True)
class InputState:
    jump: bool = False


set_global_resource(InputState)
input_state = get_global_resource(InputState).value()

Deferred Kills

kill_entity(entity_id)                  # Deferred — safe during system iteration
kill_entity(entity_id, immediate=True)  # Immediate — use outside systems

Installation

uv sync
mask clean_and_build

Requires Python 3.15+ and a C++23 compiler.

Native C++ build

The public C++ API lives under src/ecs_cub/include and is consumed as, for example, #include <ecs_cub/registry.hpp>. CMake consumers that add this repository as a subdirectory can link the ecs_cub::ecs_cub target.

An installed package exposes the same native paths through Python:

import ecs_cub

ecs_cub.get_include()      # Public C++ include directories
ecs_cub.get_libs()         # Built Python extension files
ecs_cub.get_cmake_dir()    # Directory containing EcsCubTarget.cmake

The CLI prints shell-friendly equivalents:

ecs-cub includes           # -I/path/to/ecs_cub/include
ecs-cub includes --path-only
ecs-cub libs               # One built extension path per line
ecs-cub cmake-dir

To consume an installed wheel from CMake:

execute_process(
    COMMAND "${Python_EXECUTABLE}" -c "import ecs_cub; print(ecs_cub.get_cmake_dir())"
    OUTPUT_VARIABLE ECS_CUB_CMAKE_DIR
    OUTPUT_STRIP_TRAILING_WHITESPACE
    COMMAND_ERROR_IS_FATAL ANY
)
include("${ECS_CUB_CMAKE_DIR}/EcsCubTarget.cmake")
target_link_libraries(app PRIVATE ecs_cub::ecs_cub)

For a standalone Clang build against the sibling Fond checkout:

cmake -S . -B build-cmake \
    -DCMAKE_CXX_COMPILER=clang++
cmake --build build-cmake --parallel
ctest --test-dir build-cmake --output-on-failure

Set FOND_ROOT when Fond is somewhere other than ../fond. The CMake-built Python extension is written to <build>/python/ecs_cub/api; pass -DECS_CUB_BUILD_PYTHON_MODULE=OFF when only the native library is needed. Wheel builds place their extension behind the same ecs_cub.api front door.

Enable diagnostic logging and strict Python callback errors with -DECS_CUB_DEBUG_MODE=ON -DECS_CUB_VERBOSE_LOGGING=ON -DECS_CUB_STRICT=ON. The equivalent wheel workflow is mask debug_build.

The native shutdown latch can be polled without running application logic inside a signal handler:

import signal

from ecs_cub.api import install_shutdown_signal, restore_shutdown_signal, shutdown_requested


install_shutdown_signal(signal.SIGTERM)
try:
    while not shutdown_requested():
        run_frame()
finally:
    restore_shutdown_signal(signal.SIGTERM)

consume_shutdown_request() atomically reads and clears the latch. signal_shutdown is also compatible with signal.signal() when Python-managed signal dispatch is preferred.

The GLFW/OpenGL map editor is an opt-in CMake target:

mask build map-editor
mask map-editor

Its executable lives at build-cmake/bin/map_editor; it runs with tools/map_editor as its working directory so the existing maps, icons, and sample-game asset paths remain stable.

Metadata

Release files for ecs-cub 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for ecs-cub 0.1.9
File Actions
ecs_cub-0.1.9-cp315-cp315-win_amd64.whl CPython 3.15 CPython 3.15 Windows x86-64 Details for ecs_cub-0.1.9-cp315-cp315-win_amd64.whl
ecs_cub-0.1.9-cp315-cp315-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.15 CPython 3.15 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for ecs_cub-0.1.9-cp315-cp315-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
ecs_cub-0.1.9-cp315-cp315-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.15 CPython 3.15 Linux glibc 2.26+ ARM64, Linux glibc 2.28+ ARM64 Details for ecs_cub-0.1.9-cp315-cp315-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
ecs_cub-0.1.9-cp315-cp315-macosx_15_0_arm64.whl CPython 3.15 CPython 3.15 macOS 15.0+ ARM64 Details for ecs_cub-0.1.9-cp315-cp315-macosx_15_0_arm64.whl

Total release size: 8.9 MB

Release files / ecs_cub-0.1.9-cp315-cp315-win_amd64.whl

Download URL ecs_cub-0.1.9-cp315-cp315-win_amd64.whl
Size 524.9 kB
Tags CPython 3.15 Windows x86-64
SHA-256 checksum
How to use checksums
b4b6e0b8a16d42555483e44a7338ac790f928b47769c85173e82cefdd2d22dcc
BLAKE2b-256 checksum
How to use checksums
3906c47e5d96a085530ff5a0d5d2ec75003080f156ab3fa5c6de2bbab0d9cc18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / ecs_cub-0.1.9-cp315-cp315-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL ecs_cub-0.1.9-cp315-cp315-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 4.1 MB
Tags CPython 3.15 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
05273be90538e0c0d593522a6480907d6c792b6cc128c0bd99808733eeaaf124
BLAKE2b-256 checksum
How to use checksums
786ea8c3b1e48bd333577e801e2b6b57914490d21e7c2a563fe54af3d0ad1285
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / ecs_cub-0.1.9-cp315-cp315-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL ecs_cub-0.1.9-cp315-cp315-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 4.0 MB
Tags CPython 3.15 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
3bb761104b7381a926c1e595505d583692b0fee85cf8affc7c8ed3015d07fa55
BLAKE2b-256 checksum
How to use checksums
eb67965710927e18cf1cfe40d1e547b1cbf5feb5c990edf0e5e4e46c61c2336f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / ecs_cub-0.1.9-cp315-cp315-macosx_15_0_arm64.whl

Download URL ecs_cub-0.1.9-cp315-cp315-macosx_15_0_arm64.whl
Size 305.0 kB
Tags CPython 3.15 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
e200fb9ed77a2f85b230b900a7d1610de0ee395f56ddf7d22227283a0e1038eb
BLAKE2b-256 checksum
How to use checksums
0ab818ae7dac1675f7774105e15d20d3967033745e6142d41b2c05ac954cff3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Security for ecs-cub 0.1.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for ecs_cub-0.1.9-cp315-cp315-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page