SQLAlchemy dialect for Neon's serverless HTTP endpoint
Project description
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
-poolersuffix from the hostname (Neon HTTP API requires the non-pooler host) - Constructs the
Neon-Connection-Stringheader - 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
- sqlalchemy-aurora-data-api — SQLAlchemy dialect for AWS Aurora Data API (same pattern: SQL over HTTP)
- @neondatabase/serverless — Official Neon TypeScript serverless driver
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlalchemy_neon_serverless-0.1.0.tar.gz.
File metadata
- Download URL: sqlalchemy_neon_serverless-0.1.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78dcaee34b49385f8204958b4b389e2a3ca400e51c75e3793f604e8c4b0888b7
|
|
| MD5 |
97ffbe90dc94b0b6e9b607af6e4b8072
|
|
| BLAKE2b-256 |
58cac0fc48251a9a51df4a00e93cf84be01350dc16a5ae2f1f44593e3da835c9
|
File details
Details for the file sqlalchemy_neon_serverless-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sqlalchemy_neon_serverless-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf60ad67c0bc68eed22f51952643bbbf3d83d23b7e65cf6e6828886200c5eb8a
|
|
| MD5 |
61f9da06c4c85e88e436d28b25784cb2
|
|
| BLAKE2b-256 |
6a9c1df5559ed2c9188566e0a75f761b20d09b7b109cb9766ad8b15fa1f6dd10
|