Skip to main content

Microservices framework in Python.

Project description


Overview

Kontiki is a Python microservices framework built on AMQP (aio-pika) and asyncio.

  • Write only your business logic: Kontiki manages connections to RabbitMQ, message routing (RPC, events, sessions, broadcast), service lifecycle and configuration merge for you.
  • Design service interactions as messages: combine RPC, events, broadcast and per‑instance sessions to describe how services collaborate.
  • Configuration‑driven: merged YAML config and a unified runner (cli.run) to start services the same way in development and production.

For a detailed overview of all features, see docs/features.md.


Quickstart

Install Kontiki (via pip or Poetry):

pip install kontiki

Define a simple service:

from kontiki.delegate import ServiceDelegate
from kontiki.messaging import Messenger, on_event, rpc


class MyDelegate(ServiceDelegate):
    async def setup(self):
        # init from self.container.config
        pass

    async def start(self):
        # optional: start background tasks / open connections
        pass

    async def stop(self):
        # optional: stop background tasks / close connections
        pass

    def do_something(self, x):
        # business logic
        return x * 2

    async def handle_thing(self, payload):
        # business logic
        return {"processed": payload}


class MyService:
    name = "compute-api"  # optional: if omitted, the class name "MyService" is used
    delegate = MyDelegate()
    messenger = Messenger()  # delegate: publish events, RPC to other services

    @rpc
    async def compute(self, x):
        return self.delegate.do_something(x)

    @on_event("thing_happened")
    async def on_thing(self, payload):
        result = await self.delegate.handle_thing(payload)
        await self.messenger.publish("thing_processed", result)

def run():
    cli.run(MyService, "Example Kontiki service.", version="0.1.0")

Expose it as a CLI command in pyproject.toml:

[tool.poetry.scripts]
my_service = "myapp.main:run"

Run your service:

my_service --config config.yaml

Kontiki relies on RabbitMQ. For local development and to run the examples, you can start a RabbitMQ instance via Docker with:

make run-amqp

Documentation

  • Features: docs/features.md
  • Configuration reference: docs/configuration.md
  • Example configuration: docs/kontiki-config.example.yaml
  • Contributing guidelines: CONTRIBUTING.md
  • License: LICENSE

Testing

  • Unit/lint/format checks:
    • make check
  • Integration tests (Behave: HTTP, events, RPC, tasks):
    • make integration-test

integration-test requires RabbitMQ. Locally, the Makefile target starts it automatically with Docker Compose.


Examples

Examples can be run via the Makefile (see targets such as run-rpc-service, run-rpc-example, run-simple-events-service, etc.).

Feature Example path
Basic RPC examples/rpc/
Simple events examples/events/simple/
Broadcast events examples/events/broadcast/
Event serialization examples/events/serialization/
Session-based events examples/events/session/
Periodic tasks examples/task/
Service registry (admin + client) examples/registry/
Heartbeats & degraded mode examples/heartbeat/
HTTP entrypoints examples/http/simple/

You can also have a look at the following repository kontiki-scheduler. It's an example scheduler service built with Kontiki.


Misc

Kontiki did not come out of a naming workshop but from the album Kontiki by the band Cotton Mather.
If you enjoy vintage 4-track indie pop as much as microservices, you should check it out.

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

kontiki-1.0.2.tar.gz (34.4 kB view details)

Uploaded Source

Built Distribution

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

kontiki-1.0.2-py3-none-any.whl (52.0 kB view details)

Uploaded Python 3

File details

Details for the file kontiki-1.0.2.tar.gz.

File metadata

  • Download URL: kontiki-1.0.2.tar.gz
  • Upload date:
  • Size: 34.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.11.9 Linux/6.17.9-76061709-generic

File hashes

Hashes for kontiki-1.0.2.tar.gz
Algorithm Hash digest
SHA256 0b52d4b543148c07f48ccd232d1bf1f07ce96c65a4f8de6af7b61a80e697a15a
MD5 dac546acb4d6d8bdd5d0a3e1b1533de2
BLAKE2b-256 2287452ab7e3f578b9887923d0518474f4bdbf11cd5d0ceaec878cc489e1c841

See more details on using hashes here.

File details

Details for the file kontiki-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: kontiki-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 52.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.11.9 Linux/6.17.9-76061709-generic

File hashes

Hashes for kontiki-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0f38c6bb199806bf1ac26c92378eba79900812486117d10f6fe926413eb66b80
MD5 dae609db08e724cb399c68722effeefa
BLAKE2b-256 8f4f0b010cf8c1c50e65333bee269deec88224c4c5bbd9808a62b56ac9d5786c

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