Skip to content

Add SQLAlchemy dialects incl. psycopg 3 support (#3) - #8

Closed
jmitchel3 wants to merge 2 commits into
mainfrom
fix/issue-3-dialects
Closed

Add SQLAlchemy dialects incl. psycopg 3 support (#3)#8
jmitchel3 wants to merge 2 commits into
mainfrom
fix/issue-3-dialects

Conversation

@jmitchel3

Copy link
Copy Markdown
Owner

Closes #3.

Problem

pyproject.toml registered sqlalchemy.dialects entry points pointing at timescaledb.dialect:Timescaledb*Dialect, but that module never existed. As reported in #3, the Timescaledb*Dialect classes could not be found, and timescaledb:// connection URLs could not resolve. There was also no psycopg (psycopg 3) dialect at all.

Changes

  • src/timescaledb/dialect.py (new) — defines TimescaledbPsycopg2Dialect, TimescaledbPsycopgDialect (psycopg 3), and TimescaledbAsyncpgDialect as thin subclasses of the matching PostgreSQL dialects. This library manages hypertables via explicit helper functions rather than DDL-compiler hooks, so the dialects only need to map the timescaledb scheme to the right driver. Each sets supports_statement_cache = True so SQLAlchemy query caching stays enabled.
  • pyproject.toml — registers the missing timescaledb.psycopg entry point for psycopg 3.
  • tests/test_dialect.py (new) — covers URL resolution for all four schemes and PostgreSQL subclassing.
  • README.md — documents the timescaledb:// driver schemes.
URL scheme Driver Dialect
timescaledb:// psycopg2 (default) TimescaledbPsycopg2Dialect
timescaledb+psycopg2:// psycopg2 TimescaledbPsycopg2Dialect
timescaledb+psycopg:// psycopg (psycopg 3) TimescaledbPsycopgDialect
timescaledb+asyncpg:// asyncpg TimescaledbAsyncpgDialect

Testing

  • All four URL schemes resolve to the correct dialect classes.
  • Real connection via timescaledb+psycopg:// against a timescale/timescaledb:latest-pg17 container connected successfully (TimescaleDB ext 2.28.1).
  • Full test suite: 77 passed.

Note

A new release (e.g. 0.0.7) is needed before users get the new entry points from PyPI.

The sqlalchemy.dialects entry points in pyproject.toml pointed at
timescaledb.dialect:Timescaledb*Dialect, but that module never existed,
so timescaledb:// URLs could not resolve.

- Add src/timescaledb/dialect.py defining TimescaledbPsycopg2Dialect,
  TimescaledbPsycopgDialect (psycopg 3) and TimescaledbAsyncpgDialect as
  thin subclasses of the matching PostgreSQL dialects. Each sets
  supports_statement_cache = True to keep SQLAlchemy query caching enabled.
- Register the missing timescaledb.psycopg entry point for psycopg 3.
- Add tests covering URL resolution and PostgreSQL subclassing.
- Document the timescaledb:// driver schemes in the README.
@j-paracord

Copy link
Copy Markdown

Closed as already incorporated into main. Current main includes the TimescaleDB SQLAlchemy dialect module, the timescaledb/psycopg2/psycopg/asyncpg entry points, the README driver docs, and tests/test_dialect.py. The remaining PR branch is stale against main and conflict-only at this point.

@jmitchel3

Copy link
Copy Markdown
Owner Author

Closed as already incorporated into main. Current main includes the TimescaleDB SQLAlchemy dialect module, the timescaledb/psycopg2/psycopg/asyncpg entry points, README driver docs, and tests/test_dialect.py. The remaining PR branch is stale/conflicting against main.

@jmitchel3 jmitchel3 closed this Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for psycopg

2 participants