Skip to main content

Explicit, lifecycle-scoped control of side effects

Project description

airlock

Express side effects anywhere. Control whether & when they escape.

Tests Docs codecov

Screenshot 2026-01-12 at 11 21 29 PM

tl;dr

import airlock

class Order:
    def process(self):
        self.status = "processed"
        airlock.enqueue(notify_warehouse, self.id)
        airlock.enqueue(send_confirmation_email)

The execution context decides when (and whether) your side effects actually get dispatched:

# Production API endpoint: flush at end of request
with airlock.scope():
    order.process()
# side effects dispatch here

# Migration: suppress everything
with airlock.scope(policy=airlock.DropAll()):
    order.process()
# nothing dispatched

# Test: fail if anything tries to escape
with airlock.scope(policy=airlock.AssertNoEffects()):
    order.hopefully_pure_function() # raises if any enqueue() called

# Test: surface the side effects
with airlock.scope(policy=airlock.DropAll()) as scope:
    order.process()
    assert len(scope.intents) == 2
    print((intent.name, intent.args, intent.kwargs) for intent in scope.intents)

# Admin API endpoint: selective control
with airlock.scope(policy=airlock.BlockTasks({"send_confirmation_email"})) as scope:
    order.process()
    assert len(scope.intents) == 2  # the blocked task remains enqueued while we're in the scope
# side effects dispatch or discard here -- warehouse notified, but no confirmation email sent 

Using Django? Maybe with Celery?

# settings.py
MIDDLEWARE = [
    # ... other middleware ...
    "airlock.integrations.django.AirlockMiddleware",
]

# models.py
import airlock
from . import tasks

class Order(models.Model):
    def process(self):
        self.status = "processed"
        self.save()
        airlock.enqueue(tasks.send_confirmation_email, order_id=self.id)
        airlock.enqueue(tasks.notify_warehouse, order_id=self.id)

# views.py
def checkout(request):
    order = Order.objects.get(id=request.POST['order_id'])
    order.process()
    return HttpResponse("OK")
# Celery tasks dispatch in middleware, after transaction has committed

Read more: Django integration

Installation

pip install airlock-py

Documentation

Full documentation

Key pages:

Contributing

See CONTRIBUTING.md for development setup.

License

MIT

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

airlock_py-0.1.0a1.tar.gz (46.4 kB view details)

Uploaded Source

Built Distribution

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

airlock_py-0.1.0a1-py3-none-any.whl (24.8 kB view details)

Uploaded Python 3

File details

Details for the file airlock_py-0.1.0a1.tar.gz.

File metadata

  • Download URL: airlock_py-0.1.0a1.tar.gz
  • Upload date:
  • Size: 46.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for airlock_py-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 5dc12dcd60ab71744ca027e2299ad92c6c71635438ee30f6dcada084a4e28b86
MD5 ad16f7fe9b56b8db3798ec873a3e3d03
BLAKE2b-256 e471e3b9a9b2bbc018b7216c6fcb2b45ff8e9f350218a6ecff5d9516c18c9082

See more details on using hashes here.

File details

Details for the file airlock_py-0.1.0a1-py3-none-any.whl.

File metadata

  • Download URL: airlock_py-0.1.0a1-py3-none-any.whl
  • Upload date:
  • Size: 24.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for airlock_py-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 08855a1e3dd20a6155e92f1d4633a379ffa3859c817649f87bc5001091a1bb51
MD5 cd4d9d243b264efc1a00a7e9b63a1540
BLAKE2b-256 e783791ddffbe4d983df1e13758f3aff0ac22e123fd63b4fe81f204f6c95b298

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