1. License
“Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license”
Apache 2.0 allows commercial use free of charge; it is usually only a test tool, not shipped to users.
github.com/testcontainers/testcontainers-python/blob/main/LICENSE.txt3. Used by agents' projects
Dependency in 0 public GitHub projects set up for AI coding agents that we scanned (0.0%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily; card checked Nov 10, 2026. Tap a verdict to see its source.How we checkedReport an error
What testcontainers does
Testcontainers is a free Python library that starts a real database, cache or other service in Docker just for your tests, and removes it afterwards. Your tests then talk to the same kind of Postgres or Redis you run in production instead of a fake. It needs Docker running on the machine.
What people build with it
Test against a real Postgres
Your tests for sign-up or checkout run their queries on a fresh Postgres database that disappears when the tests end.
Give each test its own Redis
Tests that use a cache or a job queue each get a clean Redis on their own port, so they can run side by side.
Run the same tests in CI
Your automated checks on every push start the same services, as long as the CI machine can reach Docker.
No leftovers after a crash
If a test run is killed halfway, a small helper container still removes the services it started.
Try a database upgrade first Idea
Run your tests on the next Postgres version by changing one image name, before you upgrade the real server.
Check database setup scripts Idea
Run your table-creation and data-change scripts on a throwaway database to see they finish without errors.
testcontainers popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How testcontainers is used
- testcontainers joined the catalog on its public numbers (9,779,247 downloads a week on PyPI and 2,322 GitHub stars), not on our project count: it is a dependency in 6 public GitHub projects of our scan, 0 of them set up for AI coding agents.
- Projects that use it most often also use pytest (100.0%), NumPy (83.3%), OpenAI Python Library (83.3%).
Often used with
More about testcontainers
Agent Skills for it
- testcontainers-integration-tests: Write integration tests using TestContainers for .NET with xUnit. Covers infrastructure testing with real databases, message queues, and cac
Alternatives
testcontainers This page
Pick fakeredis when Docker is not available and an in-memory fake of Redis is good enough for your Python tests.
Pick Moto when you only need to mock AWS services in Python tests, without containers.
Pick the Docker Python library when you want to drive the Docker Engine yourself rather than use ready test helpers.
Get started
Tell your AI assistant
“Use testcontainers for Python (pin testcontainers==4.15.0, Python 3.10+) with imports from testcontainers.community.<module>, start containers in with blocks or pytest fixtures, install the database driver separately, and use wait strategies instead of wait_for_logs.”
Make sure Docker (or another Docker-compatible runtime) is installed and running.
From github.com/testcontainers/testcontainers-python/blob/main/docs/system_requirements/docker.md
Install the library with the module you need and your own database driver.
pip install testcontainers[postgres] sqlalchemy psycopg2From github.com/testcontainers/testcontainers-python/blob/main/docs/modules/postgres.md
Start the service in a with block inside your test and run the tests with pytest.
pytest test_redis.pyFrom github.com/testcontainers/testcontainers-python/blob/main/docs/quickstart.md
Mistakes to avoid
In 4.15.0 the old paths still work but warn; our run printed "testcontainers.postgres is deprecated, use testcontainers.community.postgres instead".
String and callable predicates for wait_for_logs are deprecated in 4.15.0 and modules moved to wait strategies.
The extra no longer pulls in database drivers.
Without a reachable Docker daemon the first container start fails; our check raised DockerException.
Community modules can break in minor releases.
Questions
Does it work without Docker?
No. It needs a Docker-compatible runtime; our check without Docker failed at once with a DockerException.
Can I use Podman instead of Docker?
Yes, by setting DOCKER_HOST to the Podman socket; other runtimes are not tested as actively as Docker.
Who removes the containers if my tests crash?
A helper container called Ryuk starts with the first container and cleans up when the Python process ends or dies.
Can I start my own image, not just ready modules?
Yes. The core module runs containers from any image.