Skip to main content

pyecs

A simple implementation of the Entity-Component pattern.

PyPI - Version PyPI - Status PyPI - Python Version PyPI - License

Build Status codecov codebeat badge Code style: black Checked with mypy

Install

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

pip install pyecs

Example

from dataclasses import dataclass
from typing import Tuple

from pyecs import Store

# 1. build your components
@dataclass
class Transform:
    position: Tuple[float, float] = (0.0, 0.0)


@dataclass
class Rigidbody:
    velocity: Tuple[float, float] = (0.0, 0.0)
    acceleration: Tuple[float, float] = (0.0, 0.0)


if __name__ == "__main__":
    # 2. intialize entity-component store
    store = Store()

    # 3. add some entities
    scene = 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 everything
    while True:
        for entity in store.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

Metadata

Release files for pyecs 0.19

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

Source distribution (sdist)

Source distribution for pyecs 0.19
File Size Uploaded
pyecs-0.19.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyecs 0.19
File Interpreter ABI Platform
pyecs-0.19-py3-none-any.whl Python 3 none any Details

Total release size: 12.6 kB

Release files / pyecs-0.19.tar.gz

Download URL pyecs-0.19.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
3215b0de264d37d9ea82878c2bbae4e9d3d7a5802cfe211d262d211b45a71dc5
BLAKE2b-256 checksum
How to use checksums
0aefbbf6c6dc36b1423b20ef61be0d27cb62a655555db5c9616e0c8a0e7ba9bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.5 CPython/3.9.4 Linux/5.4.0-1043-azure

Release files / pyecs-0.19-py3-none-any.whl

Download URL pyecs-0.19-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2fb28b53903e2fd738ab9eef57a83e18f1bacbf09945441dcfdd252378016a74
BLAKE2b-256 checksum
How to use checksums
60a044d0e421afcf369ae7c451dccc0b586ea8dbadfdb203a4343132300408dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.5 CPython/3.9.4 Linux/5.4.0-1043-azure

Release history Release notifications | RSS feed

This release

0.19 This release

2 release files

0.18.1

2 release files

0.18

2 release files

0.17

2 release files

0.16

2 release files

0.15

2 release files

0.14

2 release files

0.13

2 release files

0.12

2 release files

0.11

2 release files

0.10

2 release files

0.9

2 release files

0.8

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.2

2 release files

0.1

2 release files

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