Skip to main content

A Python SDK for backend systems development @midil.io

Project description

MIDIL — Managed Interface for Data, Integration & Logic

Backend infrastructure, as a Python SDK.

MIDIL gives distributed backend systems a shared foundation — auth, eventing, HTTP, and API conventions — so teams spend less time rebuilding the same plumbing across every service.


Install

pip install pymidil

MIDIL is modular. Install only what your service needs:

Extra Installs Use when you need
pymidil[auth] httpx, pyjwt Cognito auth, JWT verification, HTTP client
pymidil[web] fastapi, starlette, uvicorn REST APIs, middleware, pagination
pymidil[aws] aioboto3 SQS consumers, EventBridge scheduling
pymidil[redis] redis Redis-backed event streaming
pymidil[mongodb] pymongo MongoDB cursor pagination
pymidil[cli] click, rich, cookiecutter Project scaffolding and service launcher
pymidil[full] everything

Requires Python 3.12+.


What's included

Auth

Outbound machine-to-machine auth and inbound JWT verification, with a pluggable interface so you're not locked into any one provider.

from pymidil.auth.cognito import CognitoClientCredentialsAuthenticator, CognitoJWTAuthorizer

# Outbound — get a token for service-to-service calls
auth = CognitoClientCredentialsAuthenticator(
    client_id="...",
    client_secret="...",
    cognito_domain="your-domain.auth.region.amazoncognito.com",
)
headers = await auth.get_headers()  # {"Authorization": "Bearer ..."}

# Inbound — verify tokens from incoming requests
authorizer = CognitoJWTAuthorizer(user_pool_id="...", region="us-east-1")
claims = await authorizer.verify(token)

Event system

A transport-agnostic event bus. Swap between SQS, Redis, or webhooks through config — your handler code stays the same.

from pymidil.event.event_bus import EventBus
from pymidil.event.subscriber.base import EventSubscriber
from pymidil.event.message import Message

class OrderPlacedHandler(EventSubscriber):
    async def handle(self, event: Message) -> None:
        ...

    async def on_error(self, event: Message, error: Exception) -> None:
        ...

bus = EventBus()
bus.subscribe(OrderPlacedHandler())

await bus.publish({"order_id": "abc-123"})
await bus.start()

Transport is configured through your service settings — no code change needed to switch from Redis to SQS in production.

HTTP client

An HTTPX-based client with built-in retry, exponential backoff, and first-class auth integration.

from pymidil.http_client import HttpClient

client = HttpClient(auth_client=auth, base_url="https://api.example.com")
response = await client.send_request("POST", "/orders", data={...})

FastAPI extensions

Drop-in middleware and dependencies for auth and JSON:API-compliant responses.

from fastapi import FastAPI, Depends
from pymidil.midilapi.middleware.auth_middleware import CognitoAuthMiddleware
from pymidil.midilapi.dependencies.jsonapi import parse_sort, parse_include

app = FastAPI()
app.add_middleware(CognitoAuthMiddleware)

@app.get("/orders")
async def list_orders(sort=Depends(parse_sort), include=Depends(parse_include)):
    ...

JSON:API

Build spec-compliant API documents without boilerplate.

from pymidil.jsonapi import Document, ResourceObject

doc = Document(
    data=ResourceObject(
        id="1",
        type="orders",
        attributes={"status": "placed", "total": 99.00},
    )
)

CLI

Scaffold and run services from the terminal.

midil init        # create a new service from a template
midil launch      # start the service with uvicorn
midil version     # show the installed SDK version

Design principles

  • Async-first. Every component is built for asyncio — no sync wrappers.
  • Opt-in by default. Nothing is installed you didn't ask for.
  • Interface-driven. Auth providers, event subscribers, retry strategies — all are abstract base classes you can swap or extend.
  • Convention over configuration. Sane defaults, with escape hatches where it matters.

License

Apache 2.0 — see LICENSE. Built at midil.io.

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

pymidil-0.1.0.tar.gz (65.2 kB view details)

Uploaded Source

Built Distribution

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

pymidil-0.1.0-py3-none-any.whl (104.8 kB view details)

Uploaded Python 3

File details

Details for the file pymidil-0.1.0.tar.gz.

File metadata

  • Download URL: pymidil-0.1.0.tar.gz
  • Upload date:
  • Size: 65.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pymidil-0.1.0.tar.gz
Algorithm Hash digest
SHA256 11df6dbac8096654a9b8d51ea1fb31e4ad70f5407e86f88b996a0c32f8244439
MD5 dce95b45bc143d6565b8310f0b4a53e4
BLAKE2b-256 87cc0a099728034f91f95009b1404b67c73de5bc286368991c4966d522d31378

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymidil-0.1.0.tar.gz:

Publisher: release.yml on chael-ai/pymidil

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

File details

Details for the file pymidil-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pymidil-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 104.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pymidil-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51b28fda7cfd7bfa1a7428514552b88746efd47db7bbdf43e6b6c1fb8101899c
MD5 7d7796fab4f6194d9b434dc21f67ba19
BLAKE2b-256 bb403d437faeb21196b166bc63872365d56971276c457d2f9e9f0c0a017fdc68

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymidil-0.1.0-py3-none-any.whl:

Publisher: release.yml on chael-ai/pymidil

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