testcontainers-postgres
PostgreSQL component of testcontainers-python.
What it is and what it does
testcontainers-postgres wraps PostgreSQL in a Docker container and exposes it for use in tests. It is a component of the larger testcontainers-python framework, which facilitates functional and integration testing by spinning up ephemeral service containers on demand. The package depends on testcontainers-core (which handles Docker lifecycle and cleanup), sqlalchemy (for connection URL generation), and psycopg2-binary (the PostgreSQL driver). You use it by instantiating a PostgresContainer with a Docker image tag, entering its context manager, and retrieving a sqlalchemy-compatible connection URL—the container starts automatically and tears down when the context exits.
The package is designed to eliminate the need for pre-configured test databases or external services. Configuration is available via environment variables (e.g., TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE, TESTCONTAINERS_RYUK_DISABLED) or runtime settings, allowing control over Docker socket paths, cleanup behavior, and container privileges.
Use it for:
- Write integration tests that need a real PostgreSQL database without managing containers manually.
- Run CI/CD pipelines that spin up isolated test databases per test suite without external dependencies.
- Test database migrations and schema changes against a fresh PostgreSQL instance each run.
- Develop multi-service tests where PostgreSQL is one of several containerized services.
- Prototype applications that depend on PostgreSQL without installing it locally.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a PostgreSQL Docker container wrapper for integration and functional testing, automatically managing container lifecycle and connection details.
Yes, if you use Docker for testing and need PostgreSQL containers. The install friction is low, maintenance is active, and there are no known vulnerabilities. However, the package is at 0.0.1rc1—clarify whether this is stable or abandoned before committing to production CI. Also verify the license before use in proprietary projects, as it is currently undeclared.
Install
testcontainers-postgres on PyPI
pip
pip install testcontainers-postgresuv
uv add testcontainers-postgrespoetry
poetry add testcontainers-postgresInstalling testcontainers-postgres
Before you install
Low install friction with three straightforward runtime dependencies. The package is actively maintained with recent commits.
License in practice
License treatment is unclear; the package metadata contains no explicit license declaration. Verify the actual license before using in proprietary or restricted contexts.
Quickstart
from testcontainers.postgres import PostgresContainer
import sqlalchemy
with PostgresContainer("postgres:16") as postgres:
engine = sqlalchemy.create_engine(postgres.get_connection_url())
with engine.begin() as connection:
result = connection.execute(sqlalchemy.text("select version()"))
version, = result.fetchone()
Requires Docker to be running and accessible; testcontainers-core manages container lifecycle via Docker socket (configurable via TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE).
Verify before relying
- Why the package remains at 0.0.1rc1 despite active maintenance—is this intentional or a pre-release that should have graduated?
- Whether the unclear license is documented elsewhere (e.g., in the repository root or GitHub).
- Compatibility and feature parity with the parent testcontainers-python project's current state.
Package facts
| License | not declared (unclear) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — testcontainers-core, sqlalchemy, psycopg2-binary |
| Maintenance | actively maintained — 1,316 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 84,200/month — #14,018 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: testcontainers_postgres-0.0.1rc1-py3-none-any.whl
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
testcontainersTestcontainers spins up Docker containers on…
permissive · top 1,000 on PyPI
testcontainers-coreProvides Docker container orchestration for…
unclear · top 15,000 on PyPI
py-pglitepy-pglite provides a zero-config PostgreSQL…
permissive · top 15,000 on PyPI
testing.postgresqlAutomatically creates and tears down temporary…
permissive · top 5,000 on PyPI
testgrestestgres orchestrates temporary PostgreSQL…
unclear · top 15,000 on PyPI
tentaclio-postgresBundles PostgreSQL connectivity and schema…
permissive · top 15,000 on PyPI
postgresProvides a lightweight abstraction layer over…
permissive · top 15,000 on PyPI
pgdbWraps PostgreSQL connections to return query…
permissive · top 15,000 on PyPI
pg0-embeddedEmbeds a PostgreSQL database directly in Python…
permissive · top 15,000 on PyPI
python-on-whalesA Python Docker client that wraps the Docker…
permissive · top 5,000 on PyPI