Skip to main content

A dependency-injection powered application framework

Project description

Engin 🏎️

codecov Downloads

Documentation: https://engin.readthedocs.io/

Source Code: https://github.com/invokermain/engin


Engin is a lightweight application framework powered by dependency injection. It helps you build and maintain everything from large monoliths to hundreds of microservices.

Features

Engin provides:

  • A fully-featured dependency injection system.
  • A robust runtime with lifecycle hooks and supervised background tasks.
  • Zero-boilerplate code reuse across applications.
  • Integrations for popular frameworks like FastAPI.
  • Full asyncio support.
  • A CLI for development utilities.

Installation

Engin is available on PyPI, install it using your favourite dependency manager:

  • pip install engin
  • poetry add engin
  • uv add engin

Example

Here’s a minimal example showing how Engin wires dependencies, manages background tasks, and handles graceful shutdown.

import asyncio
from httpx import AsyncClient
from engin import Engin, Invoke, Lifecycle, OnException, Provide, Supervisor


def httpx_client_factory(lifecycle: Lifecycle) -> AsyncClient:
    client = AsyncClient()
    lifecycle.append(client)  # easily manage the AsyncClient's lifecycle concerns
    return client


async def main(httpx_client: AsyncClient, supervisor: Supervisor) -> None:
    async def long_running_task():
        while True:
            await httpx_client.get("https://example.org/")
            await asyncio.sleep(1.0)

    supervisor.supervise(long_running_task)  # let the app run the task in a supervised manner


engin = Engin(Provide(httpx_client_factory), Invoke(main))  # define our modular application

asyncio.run(engin.run())  # run it!

Expected output (with logging enabled):

[INFO]  engin: starting engin
[INFO]  engin: startup complete
[INFO]  engin: supervising task: long_running_task
[INFO]  httpx: HTTP Request: GET https://example.org/ "HTTP/1.1 200 OK"
[INFO]  httpx: HTTP Request: GET https://example.org/ "HTTP/1.1 200 OK"
[INFO]  httpx: HTTP Request: GET https://example.org/ "HTTP/1.1 200 OK"
[DEBUG] engin: received signal: SIGINT
[DEBUG] engin: supervised task 'long_running_task' was cancelled
[INFO]  engin: stopping engin
[INFO]  engin: shutdown complete

Inspiration

Engin is heavily inspired by Uber's Fx framework for Go and the Injector framework for Python.

They are both great projects, go check them out.

Benchmarks

Automated performance benchmarks for Engin are available here.

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

engin-0.4.0.tar.gz (31.8 kB view details)

Uploaded Source

Built Distribution

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

engin-0.4.0-py3-none-any.whl (39.0 kB view details)

Uploaded Python 3

File details

Details for the file engin-0.4.0.tar.gz.

File metadata

  • Download URL: engin-0.4.0.tar.gz
  • Upload date:
  • Size: 31.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for engin-0.4.0.tar.gz
Algorithm Hash digest
SHA256 7c49c33f21e99fa74cfd60924eae7aca23bc44aa3068a9be2015a9ccacf363cf
MD5 71154ba9fea9989cd4114943c22831ed
BLAKE2b-256 d60cd471384a71ce1dc478376852e2ae057b0f72e1948e32024375d28b0e76a3

See more details on using hashes here.

File details

Details for the file engin-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: engin-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 39.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for engin-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8fc0144aca171030c05ef6d74ba0b92c04a3e90c20d092038c7cccd5d48ec6f
MD5 ac37ed6fc8473071050a5a4f532bae2e
BLAKE2b-256 d82cacc3385fa88020bd7b8571b55bbed5e444cd6f955fcf31820b5a1ba4158b

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