Skip to main content

Modern python framework

Project description

๐Ÿ Snakia Framework

Code Quality Code Size License Open Issues Commit Activity

API Reference ย โ€ขย  Telegram Chat

Snakia is a modern Python framework for creating applications with Entity-Component-System (ECS) architecture, event system, and reactive programming. Built with performance (maybe) and modularity in mind, Snakia provides a clean API for developing complex applications ranging from games to terminal user interfaces.

๐Ÿ“‹ Table of Contents

โœจ Key Features

  • ๐Ÿ—๏ธ ECS Architecture - Flexible entity-component-system for scalable game/app logic
  • ๐Ÿ“ก Event System - Asynchronous event handling with filters and priorities
  • ๐Ÿ”Œ Plugin System - Modular plugin architecture for extensibility
  • ๐ŸŽจ TUI Framework - Rich terminal user interface with reactive widgets
  • โšก Reactive Programming - Observable data streams and reactive bindings
  • ๐Ÿ› ๏ธ Rich Utilities - Decorators, properties, platform abstraction, and more
  • ๐ŸŽฏ Type Safety - Full type hints and Pydantic integration

โš ๏ธ Experimental Framework
This framework is currently in beta/experimental stage. Not all features are fully implemented, there might be bugs, and the API is subject to change. Use at your own risk! ๐Ÿšง

๐Ÿš€ Installation

Prerequisites

  • Python >= 3.12
  • pip or uv (recommended) package manager

Install from PyPi (recommended)

pip install snakia

Install from Source

git clone https://github.com/RuJect/Snakia.git
cd Snakia
pip install -e .

๐ŸŽฏ Roadmap & TODO

Here's what we're working on to make Snakia even better:

  • Plugin Isolation: restrict plugin access to only events and components statically defined in manifest
  • Async & Multithreading: implement proper async/await support and multithreading capabilities
  • Platform Support: expand platform abstraction to support more operating systems
  • Random Implementations: add various random generations implementations
  • TUI Widgets: create more ready-to-use TUI widgets and components
  • Code Documentation: add comprehensive docstrings and inline comments
  • Documentation: create detailed API documentation and tutorials

๐Ÿš€ Quick Start

from snakia.core.engine import Engine
from snakia.core.loader import Meta, Plugin, PluginProcessor
from snakia.core.ecs import Component
from snakia.types import Version

# Creating a component
class HealthComponent(Component):
    value: int = 100
    max_value: int = 100

# Creating a processor
class HealthProcessor(PluginProcessor):
    def process(self, system):
        for entity, (health,) in system.get_components(HealthComponent):
            if health.value <= 0:
                print(f"Entity {entity} died!")

# Creating a plugin
class HealthPlugin(Plugin, meta=Meta(
    name="health",
    version=Version.from_args(1, 0, 0),
    processors=(HealthProcessor,)
)):
    def on_load(self): pass
    def on_unload(self): pass

# Starting the engine
engine = Engine()
engine.loader.register(HealthPlugin)
engine.loader.load_all()
engine.start()

๐Ÿ—๏ธ Architecture

Snakia is built on a modular architecture with clear separation of concerns:

Snakia/
โ”œโ”€โ”€ core/           # Framework core
โ”‚   โ”œโ”€โ”€ engine.py   # Main engine
โ”‚   โ”œโ”€โ”€ ecs/        # Entity-Component-System
โ”‚   โ”œโ”€โ”€ es/         # Event System
โ”‚   โ”œโ”€โ”€ loader/     # Plugin loading system
โ”‚   โ”œโ”€โ”€ rx/         # Reactive programming
โ”‚   โ””โ”€โ”€ tui/        # Terminal User Interface
โ”œโ”€โ”€ decorators/    # Decorators
โ”œโ”€โ”€ property/      # Property system
โ”œโ”€โ”€ platform/      # Platform abstraction
โ”œโ”€โ”€ utils/         # Utilities
โ”œโ”€โ”€ random/        # Random number generation
โ”œโ”€โ”€ field/         # Typed fields
โ””โ”€โ”€ types/         # Special types

๐Ÿ“ฆ Examples

Health System

from snakia.core.engine import Engine
from snakia.core.ecs import Component
from snakia.core.es import Event
from snakia.core.loader import Meta, Plugin, PluginProcessor
from snakia.types import Version
from pydantic import Field

class HealthComponent(Component):
    max_value: int = Field(default=100, ge=0)
    value: int = Field(default=100, ge=0)

class DamageComponent(Component):
    damage: int = Field(ge=0)
    ticks: int = Field(default=1, ge=0)

class DeathEvent(Event):
    entity: int = Field()

class HealthProcessor(PluginProcessor):
    def process(self, system):
        # Processing damage
        for entity, (damage, health) in system.get_components(
            DamageComponent, HealthComponent
        ):
            health.value -= damage.damage
            damage.ticks -= 1
            
            if damage.ticks <= 0:
                system.remove_component(entity, DamageComponent)
            
            if health.value <= 0:
                system.remove_component(entity, HealthComponent)
                self.plugin.dispatcher.publish(DeathEvent(entity=entity))

class HealthPlugin(Plugin, meta=Meta(
    name="health",
    version=Version.from_args(1, 0, 0),
    processors=(HealthProcessor,)
)):
    def on_load(self): pass
    def on_unload(self): pass

# Usage
engine = Engine()
engine.loader.register(HealthPlugin)
engine.loader.load_all()

# Creating a player
player = engine.system.create_entity(
    HealthComponent(value=100, max_value=100)
)

# Dealing damage
engine.system.add_component(player, DamageComponent(damage=25, ticks=1))

engine.start()

TUI Application

from snakia.core.tui import CanvasChar, RenderContext
from snakia.core.tui.render import ANSIRenderer
from snakia.core.tui.widgets import TextWidget, BoxWidget, VerticalSplitWidget
import sys

class StdoutTarget:
    def write(self, text: str): sys.stdout.write(text)
    def flush(self): sys.stdout.flush()

def main():
    # Creating widgets
    title = TextWidget("Snakia TUI", CanvasChar(fg_color="cyan", bold=True))
    content = TextWidget("Welcome to Snakia!", CanvasChar(fg_color="white"))
    box = BoxWidget(20, 5, CanvasChar("โ–ˆ", fg_color="green"))
    
    # Layout
    layout = VerticalSplitWidget([title, content, box], "-")
    
    # Rendering
    renderer = ANSIRenderer(StdoutTarget())
    
    with RenderContext(renderer) as ctx:
        ctx.render(layout.render())

if __name__ == "__main__":
    main()

๐Ÿค Contributing

We welcome contributions to Snakia development! Whether you're fixing bugs, adding features, or improving documentation, your help is appreciated.

How to Contribute

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests if applicable
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Development Guidelines

  • Add type hints to all new code
  • Write clear commit messages
  • Update documentation for new features
  • Test your changes thoroughly

Project details


Download files

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

Source Distribution

snakia-0.4.2.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snakia-0.4.2-py3-none-any.whl (56.9 kB view details)

Uploaded Python 3

File details

Details for the file snakia-0.4.2.tar.gz.

File metadata

  • Download URL: snakia-0.4.2.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for snakia-0.4.2.tar.gz
Algorithm Hash digest
SHA256 008fd12f9be7b0426271287f20002fd803cef15477ed9c8072da292c23ff451c
MD5 e527bec20fae9fc22e602494bb1ae0e0
BLAKE2b-256 2f027921a6685c41cf7c880398f56a99a8a9a88231821819d807ba331ae184ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for snakia-0.4.2.tar.gz:

Publisher: pypi-publish.yml on RuJect/snakia

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snakia-0.4.2-py3-none-any.whl.

File metadata

  • Download URL: snakia-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 56.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for snakia-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6a468af25058a06be75c24d98c5bb1b5fb422d35a4a77dc1b800a915887e9c18
MD5 bdbeaf1bc0905628e20774629abdb320
BLAKE2b-256 44366a240c2b94b7166c3fa74e81a5e3ed9715a76e40c96e8c0aeeb638057db2

See more details on using hashes here.

Provenance

The following attestation bundles were made for snakia-0.4.2-py3-none-any.whl:

Publisher: pypi-publish.yml on RuJect/snakia

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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