-
Notifications
You must be signed in to change notification settings - Fork 0
mod_logic_python
Category: Logic & Scripting | Version: v1.1.0 | Source: modules/mod_logic_python/mod_logic_python.c
Python 3 scripting engine. Runs in a forked subprocess with JSON pipe bridge. Avoids CPython signal conflicts with libev. Full Python ecosystem available (pip packages).
#define PY_MAX_ROUTES 128
#define PY_BUF_SIZE 65536import portal
# Read a path
resp = portal.get("/health")
# Write a value
portal.set("/cache/session", "token123")
# Call an action
result = portal.call("/dns/resolve", body="example.com")
# Register a route
@portal.route("/myapp/analyze")
def analyze(msg):
return {"status": 200, "body": "Analysis complete"}
# Subscribe to events
@portal.on("/events/cache/*")
def on_cache_event(event):
portal.log(f"Cache event: {event[path]}")
# Logging
portal.log("Processing started")# /var/lib/portal/apps/analytics/main.py
import portal
import json
@portal.route("/myapp/report")
def generate_report(msg):
# Gather data from multiple modules
metrics = json.loads(portal.get("/metrics/cpu").body)
devices = json.loads(portal.get("/iot/devices").body)
cache_keys = json.loads(portal.get("/cache/keys").body)
report = {
"cpu_usage": metrics.get("usage", "N/A"),
"device_count": len(devices),
"cached_items": len(cache_keys),
}
return {"status": 200, "body": json.dumps(report, indent=2)}- Subprocess: Forked process, isolated from core
- JSON bridge: Messages serialized as JSON over pipe
- Full ecosystem: Use any pip package (numpy, requests, etc.)
- Safe: Python crash never affects the core
- Slower: ~1ms per handler call (serialization overhead)
Top Level System — GPL-2.0 | Website | Repository
mod_cli · mod_web · mod_node · mod_ssh · mod_config_sqlite · mod_config_psql
mod_cache · mod_kv · mod_shm · mod_queue · mod_websocket · mod_mqtt · mod_email · mod_file
mod_logic · mod_logic_lua · mod_logic_python · mod_logic_c · mod_logic_pascal
mod_metrics · mod_health · mod_sysinfo · mod_process · mod_log · mod_audit · mod_cron · mod_scheduler · mod_worker · mod_backup
mod_proxy · mod_dns · mod_http_client · mod_webhook · mod_api_gateway · mod_tunnel · mod_acme
mod_firewall · mod_crypto · mod_ldap · mod_validator
mod_iot · mod_gpio · mod_serial
mod_xz · mod_gzip · mod_template · mod_admin