Installation & Quick Start¶
Install¶
pip install pynenc-mongo
The plugin registers itself automatically via the pynenc.plugins entry point — no extra configuration needed.
Quick Start¶
PynencBuilder (Recommended)¶
from pynenc import PynencBuilder
app = (
PynencBuilder()
.app_id("my_app")
.mongo(url="mongodb://localhost:27017/pynenc")
.process_runner()
.build()
)
@app.task
def add(x: int, y: int) -> int:
return x + y
result = add(1, 2).result # 3
Environment Variables¶
PYNENC_MONGO_URL=mongodb://localhost:27017/pynenc pynenc worker
Docker Compose¶
services:
mongo:
image: mongo:7
ports: ["27017:27017"]
worker:
build: .
environment:
PYNENC_MONGO_URL: mongodb://mongo:27017/pynenc
depends_on: [mongo]
command: pynenc worker
Builder Methods¶
.mongo(url, db, host, port, username, password, auth_source)¶
Configure all MongoDB components at once — orchestrator, broker, state backend, client data store, and trigger.
# Using URL (recommended)
builder.mongo(url="mongodb://localhost:27017/pynenc")
# Using individual parameters
builder.mongo(host="localhost", port=27017, db="pynenc")
# With authentication
builder.mongo(host="localhost", port=27017, db="pynenc",
username="user", password="pass")
Parameter |
Type |
Description |
|---|---|---|
|
|
Full MongoDB URL. Overrides all other parameters. |
|
|
Database name. Ignored if |
|
|
Hostname. Ignored if |
|
|
Port. Ignored if |
|
|
Auth username. Ignored if |
|
|
Auth password. Ignored if |
|
|
Auth source database. Ignored if |
.mongo_client_data_store(min_size_to_cache, local_cache_size, max_size_to_cache)¶
Override argument cache settings. Requires .mongo() to be called first.
builder.mongo(url="mongodb://localhost:27017/pynenc").mongo_client_data_store(
min_size_to_cache=2048,
max_size_to_cache=8 * 1024 * 1024,
)
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Minimum serialized size (chars) to trigger caching |
|
|
|
Maximum items kept in the local in-process cache |
|
|
|
Maximum cacheable argument size in bytes (16 MB) |
.mongo_trigger(scheduler_interval_seconds, enable_scheduler)¶
Fine-tune the trigger scheduler. Requires .mongo() to be called first.
builder.mongo(url="mongodb://localhost:27017/pynenc").mongo_trigger(
scheduler_interval_seconds=30,
)
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
How often the scheduler checks for time-based triggers |
|
|
|
Whether to run the trigger scheduler at all |