Skip to main content

Lifecycle-first backend framework for Flask and gevent.

Project description

SPECTER

Service Primitives for Event Control, Teardown, and Execution Runtime

A lifecycle-first backend framework for Python applications built on Flask and gevent. SPECTER is designed around three ideas: explicit ownership of background work, deterministic teardown, and clear service boundaries.

Requirements

  • Python 3.9+

Stack

If you use SPECTER, the main runtime dependencies you will be building against are:

  • Flask for HTTP app and route integration
  • gevent for concurrency, timers, greenlets, and synchronization
  • Flask-SocketIO for websocket and socket event integration

Install

Install from PyPI:

pip install specter-runtime

This will install SPECTER and its required runtime dependencies.

Import it as specter:

from specter import Service, Controller, Schema, Field, boot, registry, bus

Primitives

Channel Role
Service Lifecycle owner for background work (timers, greenlets, bus subscriptions)
QueueService Queue-backed worker pool with managed startup/shutdown
Controller Feature composition root — binds routes, socket events, and state under one lifecycle
Handler Class-based Socket.IO event lifecycle
SocketIngress Shared socket fanout dispatcher (multiple listeners per event with priority)
Watcher Polling or stream-following observation loop with retry/backoff
Schema / Field Declarative payload validation and coercion
create_store Shared mutable flat state (gevent-safe)
create_model Nested runtime state graph with path selectors
create_cache Shared state with TTL expiry and bus-driven invalidation cascades
Outcome Structured success/failure result
Operation Reusable validate + perform action
ManagedProcess Subprocess lifecycle with owned stream readers
Router + route Class-based Flask Blueprint composition
registry Composition-root service locator with late binding
bus Internal synchronous pub/sub
json_endpoint Flask route decorator for consistent JSON error envelopes

Quick Examples

Service

from specter import Service

class PollingService(Service):
    def __init__(self):
        super().__init__('polling', {'tick_count': 0})

    def on_start(self):
        self.interval(self._tick, 10.0)

    def _tick(self):
        self.set_state({'tick_count': self.state.get('tick_count', 0) + 1})

service = PollingService().start()
# later
service.stop()

Controller

from flask import request
from specter import Controller, Field, Schema

class ItemController(Controller):
    name = 'items'

    schemas = {
        'create': Schema('create', {
            'name': Field(str, required=True),
            'active': Field(bool, default=True),
        })
    }

    def on_start(self):
        self.state = self.create_model('items.state', {'items': []})

    def build_routes(self, router):
        @router.route('/api/items', methods=['POST'])
        def create():
            clean = self.schema('create').require(request.get_json(silent=True) or {})
            return {'ok': True, 'name': clean['name']}

    def build_events(self, handler):
        handler.on('item_created', self._on_item_created)

    def _on_item_created(self, data=None):
        return {'ok': True}

Boot

from specter import boot

manager = boot(
    app,
    socketio,
    services=[ThumbnailService(), IndexService()],
    controllers=[ItemController()],
)

Documentation

See specter.md for the full guide and API reference.

License

Apache 2.0 — Copyright 2026 BleedingXiko

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

specter_runtime-0.1.2.tar.gz (46.9 kB view details)

Uploaded Source

Built Distribution

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

specter_runtime-0.1.2-py3-none-any.whl (64.2 kB view details)

Uploaded Python 3

File details

Details for the file specter_runtime-0.1.2.tar.gz.

File metadata

  • Download URL: specter_runtime-0.1.2.tar.gz
  • Upload date:
  • Size: 46.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for specter_runtime-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4eaf37dc51da0f0240247fd609745a88d7b5330bd3287bf166b1e3f257bfb2fa
MD5 5a39b3f8302126895f9cee2b32e80c52
BLAKE2b-256 4ac741f2e2c496806a35ece7c23fce66bfe6740f5e5e7b776778b40e3874e1fa

See more details on using hashes here.

File details

Details for the file specter_runtime-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for specter_runtime-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 43a51bc26ac0da4a3d9965d00fed6f3efc361d8fc738d9df67b86a8318737b32
MD5 ad75a639d9ed9163c5d1a00d9305b13a
BLAKE2b-256 5bcb57893dd066ce0cd02bb97975a0ba9880ef44ce53d0cce76710ee89ebc18c

See more details on using hashes here.

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