Skip to main content

sqlalchemy-neon-serverless

A SQLAlchemy dialect for Neon's serverless HTTP endpoint. Sends all SQL over HTTPS — no TCP connection, no psycopg2, no asyncpg.

This is useful when:

  • You're behind a corporate proxy that blocks PostgreSQL TCP connections (port 5432)
  • You're running in a serverless environment (Lambda, Cloud Functions, Edge) where persistent connections aren't practical
  • You want to use SQLModel or SQLAlchemy ORM with Neon without installing native PostgreSQL drivers

How it works

SQLAlchemy Engine (postgresql+neonserverless://)
  └── NeonServerlessDialect (extends PGDialect)
      └── DBAPI 2.0 Module (PEP 249)
          └── httpx POST → https://{host}/sql

Each SQL statement is sent as an HTTP POST to Neon's /sql endpoint. Every request auto-commits. The DBAPI module handles parameter conversion from SQLAlchemy's %s format to Neon's $1, $2, ... positional format.

Installation

pip install sqlalchemy-neon-serverless

# Or with uv
uv add sqlalchemy-neon-serverless

# With SQLModel support
pip install sqlalchemy-neon-serverless[sqlmodel]

Usage

SQLAlchemy Core

from sqlalchemy import create_engine, text

engine = create_engine("postgresql+neonserverless://user:pass@ep-cool-123.neon.tech/mydb")

with engine.connect() as conn:
    result = conn.execute(text("SELECT * FROM users WHERE id = :id"), {"id": 1})
    print(result.fetchone())

SQLAlchemy ORM

from sqlalchemy import create_engine, Column, String
from sqlalchemy.orm import DeclarativeBase, Session

engine = create_engine("postgresql+neonserverless://user:pass@ep-cool-123.neon.tech/mydb")

class Base(DeclarativeBase):
    pass

class User(Base):
    __tablename__ = "users"
    id = Column(String, primary_key=True)
    name = Column(String)

with Session(engine) as session:
    users = session.query(User).all()

SQLModel

from sqlmodel import Field, Session, SQLModel, create_engine, select

engine = create_engine("postgresql+neonserverless://user:pass@ep-cool-123.neon.tech/mydb")

class User(SQLModel, table=True):
    id: str = Field(primary_key=True)
    name: str

with Session(engine) as session:
    users = session.exec(select(User)).all()

Connection URL format

postgresql+neonserverless://user:password@endpoint-host.neon.tech/dbname

The dialect automatically:

  • Strips the -pooler suffix from the hostname (Neon HTTP API requires the non-pooler host)
  • Constructs the Neon-Connection-String header
  • Sends queries to https://{host}/sql

Environment variables

Variable Description
SSL_CERT_FILE Path to CA bundle for TLS verification. Set to "" to disable verification (corporate proxy).

Limitations

  • No transactions: Each HTTP request auto-commits. session.rollback() is a no-op.
  • No server-side cursors: All results are fetched in a single HTTP response.
  • No streaming: Large result sets are fully loaded into memory.
  • No LISTEN/NOTIFY: WebSocket-based features are not supported.

Inspired by

License

MIT

Release files for sqlalchemy-neon-serverless 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlalchemy-neon-serverless 0.1.0
File Size Uploaded
sqlalchemy_neon_serverless-0.1.0.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlalchemy-neon-serverless 0.1.0
File Interpreter ABI Platform
sqlalchemy_neon_serverless-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release files / sqlalchemy_neon_serverless-0.1.0.tar.gz

Download URL sqlalchemy_neon_serverless-0.1.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
78dcaee34b49385f8204958b4b389e2a3ca400e51c75e3793f604e8c4b0888b7
BLAKE2b-256 checksum
How to use checksums
58cac0fc48251a9a51df4a00e93cf84be01350dc16a5ae2f1f44593e3da835c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / sqlalchemy_neon_serverless-0.1.0-py3-none-any.whl

Download URL sqlalchemy_neon_serverless-0.1.0-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bf60ad67c0bc68eed22f51952643bbbf3d83d23b7e65cf6e6828886200c5eb8a
BLAKE2b-256 checksum
How to use checksums
6a9c1df5559ed2c9188566e0a75f761b20d09b7b109cb9766ad8b15fa1f6dd10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page