Pre-release
This release is a pre-release and may not be stable for production use.
airlock
Express side effects anywhere. Control whether & when they escape.
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
Key pages:
- The Problem - Why airlock exists
- Core Model - The 3 concerns (Policy/Executor/Scope)
- Nesting - Nested scopes and safety
- Alternatives - Do I really need this...?
Contributing
See CONTRIBUTING.md for development setup.
License
MIT
Metadata
Release files for airlock-py 0.1.0a3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| airlock_py-0.1.0a3.tar.gz | 46.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| airlock_py-0.1.0a3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 71.2 kB
Release files / airlock_py-0.1.0a3.tar.gz
| Download URL | airlock_py-0.1.0a3.tar.gz |
|---|---|
| Size | 46.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f929cb84a14f4988627ddabb6881ffc59055e17587805eae5305a48c3cf96ca2
|
|
BLAKE2b-256 checksum How to use checksums |
df96eb00277b14336f815faff788a0347a641672803e840f2270b38c528e84fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.6
|
Release files / airlock_py-0.1.0a3-py3-none-any.whl
| Download URL | airlock_py-0.1.0a3-py3-none-any.whl |
|---|---|
| Size | 24.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6a13793e4d7dca8e47d5b6655c6ebb5c5591f2b7d71ac78e43d0f05cbb56770b
|
|
BLAKE2b-256 checksum How to use checksums |
4c38c2734078f2cb3a47cc2c40e94a02bd9002ca5eaf7a7d4a28665a5e040d6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.6
|