Neon (Serverless PostgreSQL)

platform · active · verified Tue Mar 24

Neon is a serverless PostgreSQL platform (acquired by Databricks May 2025 for ~$1B). Not a Python package — connect using standard PostgreSQL drivers (psycopg2, psycopg, asyncpg, SQLAlchemy). Two connection string types: pooled (-pooler in hostname, via PgBouncer) and direct. Pooled is now the default in Neon Console. Critical: always include sslmode=require. asyncpg with pooled connections requires statement_cache_size=0.

Warnings

Install

Imports

Quickstart

Minimal Neon PostgreSQL connection with psycopg2.

# pip install psycopg2-binary python-dotenv
import psycopg2
from dotenv import load_dotenv
import os

load_dotenv()

# Use pooled URL from Neon Console (includes -pooler in hostname)
conn = psycopg2.connect(os.environ['DATABASE_URL'])
# DATABASE_URL=postgresql://user:pass@ep-xxx-pooler.region.aws.neon.tech/neondb?sslmode=require

cur = conn.cursor()
cur.execute('SELECT version()')
print(cur.fetchone())

cur.execute(
    'SELECT * FROM users WHERE id = %s',
    (1,)
)
rows = cur.fetchall()

cur.close()
conn.close()

view raw JSON →