Skip to main content

matimo-postgres

PostgreSQL tools for Matimo — execute SQL queries safely with policy-gated approval.

PyPI Docs


Installation

pip install matimo matimo-postgres

Available Tools (1 Tool)

Tool Description
execute-sql Execute a SQL query against a PostgreSQL database

The execute-sql tool is marked requires_approval: true — destructive operations (INSERT, UPDATE, DELETE, DROP) trigger HITL approval by default.


Quick Start

import asyncio
from matimo import Matimo, InitOptions
from matimo_postgres import get_tools_path

async def main():
    # Auto-approve for read-only usage (CI/CD)
    matimo = await Matimo.init(
        get_tools_path(),
        InitOptions(on_hitl=lambda req: {'approved': True, 'reason': 'auto'}),
    )

    # Run a SELECT query
    result = await matimo.execute('execute-sql', {
        'query': 'SELECT id, name FROM users LIMIT 10',
    })
    print(result)

asyncio.run(main())

With Interactive Approval (Recommended for Writes)

async def ask_user(request) -> dict:
    print(f"\nSQL requires approval:\n{request.params.get('query')}")
    answer = input("Run this query? [y/n]: ").strip()
    return {'approved': answer == 'y', 'reason': 'user reviewed'}

matimo = await Matimo.init(
    get_tools_path(),
    InitOptions(on_hitl=ask_user),
)

# This will prompt before executing
await matimo.execute('execute-sql', {
    'query': 'DELETE FROM sessions WHERE expired_at < NOW()',
})

Authentication

export DATABASE_URL="postgresql://user:password@localhost:5432/mydb"
# or individual params
export POSTGRES_HOST="localhost"
export POSTGRES_PORT="5432"
export POSTGRES_DB="mydb"
export POSTGRES_USER="myuser"
export POSTGRES_PASSWORD="mypassword"

Security Notes

  • All SQL queries go through Matimo's content validator — SSRF and injection patterns are detected
  • The tool has requires_approval: true — writes trigger approval by default
  • Use a read-only database user for agent workloads when possible
  • Consider a policy file to restrict allowed SQL patterns

Documentation


Links

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matimo_postgres-0.1.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

matimo_postgres-0.1.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file matimo_postgres-0.1.2.tar.gz.

File metadata

  • Download URL: matimo_postgres-0.1.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for matimo_postgres-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0ecce2b91e0efd66494b221235559471f3e17a51f871967d68691c4fefc4bbab
MD5 68e51a7bfffdb166406a903ea7a7d43e
BLAKE2b-256 dbf35c4927df81d92df12d9a2967b690f63be417be3ad205abfe5250d21d0032

See more details on using hashes here.

File details

Details for the file matimo_postgres-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for matimo_postgres-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d2d78970ed753b31e119240b98a59afe936551f045f8b293fd8375c30db20513
MD5 88b2aac1c475156059f912ec47139b15
BLAKE2b-256 c433870dbf76f50a6d4cb2fcae1cb328f70822aa19a29bf8fbd5fd034cf047e4

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 Sentry Error logging StatusPage Status page