[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
![PyPI - Version](https://img.shields.io/pypi/v/testcontainers)
[![PyPI - License](https://img.shields.io/pypi/l/testcontainers.svg)](https://github.com/testcontainers/testcontainers-python/blob/main/LICENSE)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/testcontainers.svg)](https://pypi.python.org/pypi/testcontainers)
[![codecov](https://codecov.io/gh/testcontainers/testcontainers-python/branch/master/graph/badge.svg)](https://codecov.io/gh/testcontainers/testcontainers-python)
![Core Tests](https://github.com/testcontainers/testcontainers-python/actions/workflows/ci-core.yml/badge.svg)
![Community Tests](https://github.com/testcontainers/testcontainers-python/actions/workflows/ci-community.yml/badge.svg)
[![Docs](https://readthedocs.org/projects/testcontainers-python/badge/?version=latest)](http://testcontainers-python.readthedocs.io/en/latest/?badge=latest)
[![Codespace](https://github.com/codespaces/badge.svg)](https://codespaces.new/testcontainers/testcontainers-python)
# Testcontainers Python
`testcontainers-python` facilitates the use of Docker containers for functional and integration testing.
For more information, see [the docs][readthedocs].
[readthedocs]: https://testcontainers-python.readthedocs.io/en/latest/
## Getting Started
```pycon
>>> 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()
>>> version
'PostgreSQL 16...'
```
The snippet above will spin up a postgres database in a container. The `get_connection_url()` convenience method returns a `sqlalchemy` compatible url we use to connect to the database and retrieve the database version.
## Contributing / Development / Release
See [CONTRIBUTING.md](.github/CONTRIBUTING.md) for more details.
## Configuration
| Env Variable | Example | Description |
| --------------------------------------- | --------------------------- | ---------------------------------------------------------------------------------- |
| `TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE` | `/var/run/docker.sock` | Path to Docker's socket used by ryuk |
| `TESTCONTAINERS_RYUK_PRIVILEGED` | `false` | Run ryuk as a privileged container |
| `TESTCONTAINERS_RYUK_DISABLED` | `false` | Disable ryuk |
| `RYUK_CONTAINER_IMAGE` | `testcontainers/ryuk:0.8.1` | Custom image for ryuk |
| `RYUK_RECONNECTION_TIMEOUT` | `10s` | Reconnection timeout for Ryuk TCP socket before Ryuk reaps all dangling containers |
Raw data
{
"_id": null,
"home_page": null,
"name": "testcontainers",
"maintainer": "Balint Bartha",
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": "totallyzen@users.noreply.github.com",
"keywords": "testing, logging, docker, test automation",
"author": "Sergey Pirogov",
"author_email": "automationremarks@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/2e/9a/e1ac5231231192b39302fcad7de2c0dbfc718c0636d7e28917c30ec57c41/testcontainers-4.9.0.tar.gz",
"platform": null,
"description": "[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n![PyPI - Version](https://img.shields.io/pypi/v/testcontainers)\n[![PyPI - License](https://img.shields.io/pypi/l/testcontainers.svg)](https://github.com/testcontainers/testcontainers-python/blob/main/LICENSE)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/testcontainers.svg)](https://pypi.python.org/pypi/testcontainers)\n[![codecov](https://codecov.io/gh/testcontainers/testcontainers-python/branch/master/graph/badge.svg)](https://codecov.io/gh/testcontainers/testcontainers-python)\n![Core Tests](https://github.com/testcontainers/testcontainers-python/actions/workflows/ci-core.yml/badge.svg)\n![Community Tests](https://github.com/testcontainers/testcontainers-python/actions/workflows/ci-community.yml/badge.svg)\n[![Docs](https://readthedocs.org/projects/testcontainers-python/badge/?version=latest)](http://testcontainers-python.readthedocs.io/en/latest/?badge=latest)\n\n[![Codespace](https://github.com/codespaces/badge.svg)](https://codespaces.new/testcontainers/testcontainers-python)\n\n# Testcontainers Python\n\n`testcontainers-python` facilitates the use of Docker containers for functional and integration testing.\n\nFor more information, see [the docs][readthedocs].\n\n[readthedocs]: https://testcontainers-python.readthedocs.io/en/latest/\n\n## Getting Started\n\n```pycon\n>>> from testcontainers.postgres import PostgresContainer\n>>> import sqlalchemy\n\n>>> with PostgresContainer(\"postgres:16\") as postgres:\n... engine = sqlalchemy.create_engine(postgres.get_connection_url())\n... with engine.begin() as connection:\n... result = connection.execute(sqlalchemy.text(\"select version()\"))\n... version, = result.fetchone()\n>>> version\n'PostgreSQL 16...'\n```\n\nThe snippet above will spin up a postgres database in a container. The `get_connection_url()` convenience method returns a `sqlalchemy` compatible url we use to connect to the database and retrieve the database version.\n\n## Contributing / Development / Release\n\nSee [CONTRIBUTING.md](.github/CONTRIBUTING.md) for more details.\n\n## Configuration\n\n| Env Variable | Example | Description |\n| --------------------------------------- | --------------------------- | ---------------------------------------------------------------------------------- |\n| `TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE` | `/var/run/docker.sock` | Path to Docker's socket used by ryuk |\n| `TESTCONTAINERS_RYUK_PRIVILEGED` | `false` | Run ryuk as a privileged container |\n| `TESTCONTAINERS_RYUK_DISABLED` | `false` | Disable ryuk |\n| `RYUK_CONTAINER_IMAGE` | `testcontainers/ryuk:0.8.1` | Custom image for ryuk |\n| `RYUK_RECONNECTION_TIMEOUT` | `10s` | Reconnection timeout for Ryuk TCP socket before Ryuk reaps all dangling containers |\n\n",
"bugtrack_url": null,
"license": null,
"summary": "Python library for throwaway instances of anything that can run in a Docker container",
"version": "4.9.0",
"project_urls": {
"GitHub": "https://github.com/testcontainers/testcontainers-python",
"Issue Tracker": "https://github.com/testcontainers/testcontainers-python/issues"
},
"split_keywords": [
"testing",
" logging",
" docker",
" test automation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3ef86425ff800894784160290bcb9737878d910b6da6a08633bfe7f2ed8c9ae3",
"md5": "7b9f4a8e1de3bdc1d0f4ea3118090f13",
"sha256": "c6fee929990972c40bf6b91b7072c94064ff3649b405a14fde0274c8b2479d32"
},
"downloads": -1,
"filename": "testcontainers-4.9.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7b9f4a8e1de3bdc1d0f4ea3118090f13",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 105324,
"upload_time": "2024-12-10T17:25:36",
"upload_time_iso_8601": "2024-12-10T17:25:36.752756Z",
"url": "https://files.pythonhosted.org/packages/3e/f8/6425ff800894784160290bcb9737878d910b6da6a08633bfe7f2ed8c9ae3/testcontainers-4.9.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2e9ae1ac5231231192b39302fcad7de2c0dbfc718c0636d7e28917c30ec57c41",
"md5": "169d669e9a7ffa519f2ba0296b8e13cf",
"sha256": "2cd6af070109ff68c1ab5389dc89c86c2dc3ab30a21ca734b2cb8f0f80ad479e"
},
"downloads": -1,
"filename": "testcontainers-4.9.0.tar.gz",
"has_sig": false,
"md5_digest": "169d669e9a7ffa519f2ba0296b8e13cf",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 64612,
"upload_time": "2024-12-10T17:25:39",
"upload_time_iso_8601": "2024-12-10T17:25:39.674095Z",
"url": "https://files.pythonhosted.org/packages/2e/9a/e1ac5231231192b39302fcad7de2c0dbfc718c0636d7e28917c30ec57c41/testcontainers-4.9.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-10 17:25:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "testcontainers",
"github_project": "testcontainers-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "testcontainers"
}