ecs-cub
A high-performance Entity Component System with a C++26 core and native CPython 3.15 bindings.
⚠️ Research project — not production ready. We're exploring, not shipping.
Features
- Registry — one native Python object owns entities, systems, queries, tags, groups, signals, and pub/sub
- Entities — lightweight integer IDs with freelist reuse and optional generation-checked
Entityhandles - Components — any Python object, indexed by its exact type
- Queries — reusable query signatures, exclusion filters (
Exclude(Dead)), andNOT_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 — native exact-type storage owned by the registry, 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
Resource storage has a focused benchmark comparing the native registry, the historical Python resource API, and a direct dictionary. It rotates measurement order, checks stored identities before timing, and reports median nanoseconds across exact-type stores containing 1, 32, and 128 resources.
mask benchmark-resources
mask benchmark-resources 100000 5 # iterations, rounds
Use python benchmarks/resource_storage.py --help for custom store sizes and warmup counts. The benchmark is descriptive;
it does not impose performance thresholds on CI.
For CPython 3.15 sampling profiles of the Python workload around the native resource implementation:
mask profile-resources # mixed workload for 15 seconds
mask profile-resources lookup 30 # lookup-only workload for 30 seconds
mask profile-resources mutation 30
mask profile-resources bulk 30
The profiling command uses CPU-mode sampling at 5 kHz with opcode and native-frame markers. It writes an uncompressed
binary profile and replays it as both /tmp/ecs-cub-resources-<workload>.html and
/tmp/ecs-cub-resources-<workload>-heatmap/index.html. The flamegraph is useful for call-stack-heavy workloads such as
mixed; the opcode heatmap gives a clearer view of tight loops such as bulk. The profiler's native markers are opaque
boundaries rather than symbolized C++ stacks. Sampling them on macOS requires sudo; the workload itself is available
without elevated privileges through python -m benchmarks.profile_resources --help.
Use Instruments Time Profiler when the C++ implementation itself is the target:
mask profile-resources-native bulk 30
This writes a uniquely named .trace under /tmp and prints both its path and the command to open it. The extension
contains native symbols, so Time Profiler can attribute samples inside the resource operations; optimization and inlining
may still merge small functions into their callers.
Features
Entities
from ecs_cub import Health, Inventory, Position, Velocity, registry
# Lightweight integer IDs
entity_id = registry.create_entity(Position(0, 0), Velocity(1, 0))
# Or a generation-checked wrapper that cannot alias a recycled entity ID
player = registry.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 import Exclude, Position, Velocity, registry
query = registry.create_query(Position, Velocity)
for entity_id, (pos, vel) in registry.get_components(query):
pos.x += vel.dx
# Exclusion — entities with Position but NOT Dead
query = registry.create_query(Position, Exclude(Dead))
Systems
Two patterns, pick what fits:
from ecs_cub import Position, SystemBase, Velocity, registry
# 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
registry.world_update(dt=1 / 60)
# Pull model — you ask for results when you want them
sys_idx = registry.register_system(Position, Velocity)
results = registry.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
registry.tag_entity(entity_id, "player")
player_id = registry.get_entity_by_tag("player")
# Groups — 1:many, entities can belong to multiple groups
registry.group_entity(entity_id, "enemies")
registry.group_entity(entity_id, "bosses") # same entity, two groups
enemies = registry.get_entities_by_group("enemies")
Events & Pub/Sub
# Signals — 1:1 handler
registry.connect("player_died", on_player_death)
registry.fire("player_died", player_id)
# Pub/Sub — 1:many subscribers
registry.subscribe("damage_dealt", log_damage)
registry.subscribe("damage_dealt", update_ui)
registry.publish("damage_dealt", entity_id, amount)
Internal lifecycle events are auto-published on _entity:created, _entity:killed, _component:added, and _component:removed.
Registry() returns the same canonical object as registry; ecs-cub does not create a second hidden world. The historical
free functions remain compatibility aliases to these bound methods.
Resources
Resources are indexed by their exact Python type in a bounded native open-addressing store. Registry-local and
process-global storage each accept at most MAX_RESOURCES (128) exact types. find_resource() is the direct required
path and raises KeyError when a resource is absent; get_resource() is the optional path and returns None.
from fond import struct
from ecs_cub.api import find_resource, set_resource
@struct(slots=True)
class FrameClock:
delta_time: float = 0.0
clock = FrameClock(delta_time=0.016)
set_resource(clock)
dt = find_resource(FrameClock).delta_time
There is one resource slot per exact type, so setting another FrameClock replaces the existing value without consuming
another capacity slot. 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 find_global_resource, set_global_resource
@struct(slots=True)
class InputState:
jump: bool = False
set_global_resource(InputState)
input_state = find_global_resource(InputState)
Deferred Kills
registry.kill_entity(entity_id) # Deferred — safe during system iteration
registry.kill_entity(entity_id, immediate=True) # Immediate — use outside systems
Installation
uv sync
mask clean_and_build
Requires Python 3.15+ and a C++26 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.
Metadata
Release files for ecs-cub 0.1.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| ecs_cub-0.1.11-cp315-cp315-win_amd64.whl | CPython 3.15 | CPython 3.15 | Windows x86-64 | Details for ecs_cub-0.1.11-cp315-cp315-win_amd64.whl |
| ecs_cub-0.1.11-cp315-cp315-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl | CPython 3.15 | CPython 3.15 | Linux glibc 2.26+ x86-64, Linux glibc 2.28+ x86-64 | Details for ecs_cub-0.1.11-cp315-cp315-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl |
| ecs_cub-0.1.11-cp315-cp315-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl | CPython 3.15 | CPython 3.15 | Linux glibc 2.24+ ARM64, Linux glibc 2.28+ ARM64 | Details for ecs_cub-0.1.11-cp315-cp315-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl |
| ecs_cub-0.1.11-cp315-cp315-macosx_15_0_arm64.whl | CPython 3.15 | CPython 3.15 | macOS 15.0+ ARM64 | Details for ecs_cub-0.1.11-cp315-cp315-macosx_15_0_arm64.whl |
Total release size: 1.2 MB
Release files / ecs_cub-0.1.11-cp315-cp315-win_amd64.whl
| Download URL | ecs_cub-0.1.11-cp315-cp315-win_amd64.whl |
|---|---|
| Size | 433.9 kB |
| Tags | CPython 3.15 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
a1396e62f4744b4054956b86770687796a9d032df2f304a2f3ca860c05a3af1a
|
|
BLAKE2b-256 checksum How to use checksums |
bde0e851116d1746821639ff39d7955932f39a0d626f8d33851206d112cf1756
|
| 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 11, 2026.
Transparency logRelease files / ecs_cub-0.1.11-cp315-cp315-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl
| Download URL | ecs_cub-0.1.11-cp315-cp315-manylinux_2_26_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 291.4 kB |
| Tags | CPython 3.15 Linux glibc 2.26+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
762a1ca517f1cba02ec694de23893f8f0e56669129b3c18657148763d097490d
|
|
BLAKE2b-256 checksum How to use checksums |
a22d6dda56246ea30bec68f03985501beced7f453334adb654386525688269d3
|
| 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 11, 2026.
Transparency logRelease files / ecs_cub-0.1.11-cp315-cp315-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
| Download URL | ecs_cub-0.1.11-cp315-cp315-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 276.7 kB |
| Tags | CPython 3.15 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64 |
|
SHA-256 checksum How to use checksums |
1ed0bcf72b6da978314535f702da42cf86c31b4038cf93ae84cab1ab1b30e227
|
|
BLAKE2b-256 checksum How to use checksums |
655af8737eea2476390898173248f5f73641c5ba9b533e44fac51e066dca5d0b
|
| 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 11, 2026.
Transparency logRelease files / ecs_cub-0.1.11-cp315-cp315-macosx_15_0_arm64.whl
| Download URL | ecs_cub-0.1.11-cp315-cp315-macosx_15_0_arm64.whl |
|---|---|
| Size | 163.9 kB |
| Tags | CPython 3.15 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e513e1ea3bae70d1a0100b0dccbf36498f18dd071c3277baf74853b8f93107bb
|
|
BLAKE2b-256 checksum How to use checksums |
29de24362bef65474294b5a93bd646dceaf20a55bfac5200712077c8feb3398a
|
| 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 11, 2026.
Transparency logSecurity for ecs-cub 0.1.11
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.
Attestation for ecs_cub-0.1.11-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 11, 2026.
Transparency logA 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.