Skip to main content

Shared PostgreSQL store adapter for ActionGate, BudgetGate, RuleGate, and AuditGate

Project description

actiongate-postgres

Shared PostgreSQL store adapter for ActionGate, BudgetGate, RuleGate, and AuditGate.

Uses psycopg (psycopg3) with connection pooling. One pool shared across all gate stores.

Install

pip install actiongate-postgres

# Install with specific gate support:
pip install actiongate-postgres[actiongate]
pip install actiongate-postgres[all]  # all four gates

Quickstart

import psycopg
from actiongate import Engine, Gate, Policy
from actiongate_postgres import ConnectionManager, ActionGatePostgresStore, create_tables

# Create shared pool
mgr = ConnectionManager("postgresql://localhost/mydb")

# Create tables (idempotent)
with mgr.pool.connection() as conn:
    create_tables(conn)

# Wire store to engine
store = ActionGatePostgresStore(mgr)
engine = Engine(store=store)

engine.register(Gate("api", "send_email", "user-42"), Policy(max_calls=5, window=60))
result = engine.check(Gate("api", "send_email", "user-42"))
print(result)  # Decision(status=ALLOW, ...)

mgr.close()

Async

from actiongate_postgres import AsyncConnectionManager, AsyncActionGatePostgresStore

async with AsyncConnectionManager("postgresql://localhost/mydb") as mgr:
    store = AsyncActionGatePostgresStore(mgr)
    # use with async engine...

Multiple Gates, One Pool

from actiongate_postgres import (
    ConnectionManager,
    ActionGatePostgresStore,
    BudgetGatePostgresStore,
    AuditGatePostgresStore,
    create_tables,
)

mgr = ConnectionManager("postgresql://localhost/mydb")

with mgr.pool.connection() as conn:
    create_tables(conn)

ag_store = ActionGatePostgresStore(mgr)
bg_store = BudgetGatePostgresStore(mgr)
audit_store = AuditGatePostgresStore(mgr)

Testing

# Start PostgreSQL
docker compose up -d

# Run tests
DATABASE_URL="postgresql://actiongate:actiongate@localhost/actiongate_test" pytest tests/ -v

License

Apache-2.0

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

actiongate_postgres-0.1.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

actiongate_postgres-0.1.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: actiongate_postgres-0.1.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for actiongate_postgres-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6dddbbbc7d45a22a9b5202d510dda5b6a248d4668dc8cf0995e96af25c60e39c
MD5 0b084ba9bb69ef96a0180e334e3ff6f2
BLAKE2b-256 df6edfb72d0e887f275936c62108e266ac2523784992d39b1b904e9ea7dd3ae4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for actiongate_postgres-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b186ecfb5fdf9971bce238d888eb047e01aa1496085556c09f51b1f0f222071
MD5 1b41450137141e4f9feb258b2832d1ae
BLAKE2b-256 20bf9442922698464c8b838bff352da944f28d26927b4121a6318ae60dbe7b26

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