CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/postgresql-python-best-practices

PostgreSQL patterns for Python with psycopg and asyncpg — connection pooling,

99

1.15x
Quality

99%

Does it follow best practices?

Impact

99%

1.15x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

pg-pool-config.jsonverifiers/

{
  "instruction": "Configure PostgreSQL connection pools with proper sizing, timeouts, lifecycle management, and environment-based credentials",
  "relevant_when": "Agent sets up PostgreSQL database connections in Python, configures psycopg or asyncpg, or creates a database module",
  "context": "PostgreSQL Python apps must use connection pools (psycopg_pool.ConnectionPool or asyncpg.create_pool) with min_size, max_size, timeout, and max_lifetime settings. Database URLs must come from environment variables, never hardcoded. Pools must be closed on application shutdown via atexit, lifespan handlers, or framework lifecycle hooks. SSL/sslmode should be configured for production. Never create new connections per request.",
  "sources": [
    {
      "type": "file",
      "filename": "skills/postgresql-python-best-practices/SKILL.md",
      "tile": "tessl-labs/postgresql-python-best-practices@0.2.0"
    }
  ],
  "checklist": [
    {
      "name": "connection-pool-used",
      "rule": "Agent uses psycopg_pool.ConnectionPool or asyncpg.create_pool for database connections, never creating individual connections per request with psycopg.connect() or asyncpg.connect() in request handlers",
      "relevant_when": "Agent sets up PostgreSQL connections in Python"
    },
    {
      "name": "pool-min-max-size",
      "rule": "Connection pool is configured with both min_size and max_size parameters to control connection count",
      "relevant_when": "Agent creates a psycopg_pool or asyncpg pool"
    },
    {
      "name": "pool-timeout",
      "rule": "Connection pool has a timeout setting (timeout for psycopg_pool, command_timeout for asyncpg) so requests fail fast instead of hanging indefinitely",
      "relevant_when": "Agent creates a connection pool"
    },
    {
      "name": "database-url-from-env",
      "rule": "Database connection string is read from an environment variable (e.g., os.getenv('DATABASE_URL')) not hardcoded with credentials in source code",
      "relevant_when": "Agent configures database connection URL"
    },
    {
      "name": "pool-shutdown-cleanup",
      "rule": "Pool is closed on application shutdown using atexit.register(pool.close), FastAPI lifespan handler, or equivalent framework lifecycle hook",
      "relevant_when": "Agent sets up a connection pool in an application"
    },
    {
      "name": "context-manager-for-connections",
      "rule": "Connections are obtained via context managers ('with pool.connection()' or 'async with pool.acquire()') to ensure automatic return to the pool, never manually acquired without release",
      "relevant_when": "Agent writes code that obtains database connections from a pool"
    }
  ]
}

tile.json