Skip to main content

Library provides lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container

Project description


Build Status PyPI Documentation Status

Python port for testcontainers-java that allows using docker containers for functional and/or integration testing.

Testcontainers-python provides capabilities to spin up a docker containers for test purposes would that be a database, Selenium web browser or any other cotainer.

Currently available features:

  • Selenium Grid containers
  • Selenium Standalone containers
  • MySql Db container
  • MariaDb container
  • PostgreSQL Db container
  • Generic docker containers

Quick start


The testcontainers module is available from PyPI at:

and can be installed using pip, depending on which containers you need:

pip install testcontainers[mysql]
pip install testcontainers[postgresql]
pip install testcontainers[selenium]
# or with multiple
pip install testcontainers[mysql,postgresql,selenium]

Basic usage

Database containers

Allows to spin up docker database images such as MySQL, PostgreSQL, MariaDB and Oracle XE.

MySQL example

    config = MySqlContainer('mysql:5.7.17')
    with config as mysql:
        e = sqlalchemy.create_engine(mysql.get_connection_url())
        result = e.execute("select version()")

It will spin up MySQL version 5.7. Then you can connect to database using get_connection_url() method which returns sqlalchemy compatible url in format dialect+driver://username:password@host:port/database.

Detailed documentation

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for testcontainers, version 2.5
Filename, size File type Python version Upload date Hashes
Filename, size testcontainers-2.5.tar.gz (8.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page