[![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/1f/72/c58d84f5704c6caadd9f803a3adad5ab54ac65328c02d13295f40860cf33/testcontainers-4.8.2.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.8.2",
"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": "80775ac0dff2903a033d83d971fd85957356abdb66a327f3589df2b3d1a586b4",
"md5": "d86a9568390207dc43e9c98288d0267e",
"sha256": "9e19af077cd96e1957c13ee466f1f32905bc6c5bc1bc98643eb18be1a989bfb0"
},
"downloads": -1,
"filename": "testcontainers-4.8.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d86a9568390207dc43e9c98288d0267e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 104326,
"upload_time": "2024-10-14T03:50:16",
"upload_time_iso_8601": "2024-10-14T03:50:16.957912Z",
"url": "https://files.pythonhosted.org/packages/80/77/5ac0dff2903a033d83d971fd85957356abdb66a327f3589df2b3d1a586b4/testcontainers-4.8.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1f72c58d84f5704c6caadd9f803a3adad5ab54ac65328c02d13295f40860cf33",
"md5": "3506d3de2b023805f0a6e5e6e4c4e0f5",
"sha256": "dd4a6a2ea09e3c3ecd39e180b6548105929d0bb78d665ce9919cb3f8c98f9853"
},
"downloads": -1,
"filename": "testcontainers-4.8.2.tar.gz",
"has_sig": false,
"md5_digest": "3506d3de2b023805f0a6e5e6e4c4e0f5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 63590,
"upload_time": "2024-10-14T03:50:19",
"upload_time_iso_8601": "2024-10-14T03:50:19.058199Z",
"url": "https://files.pythonhosted.org/packages/1f/72/c58d84f5704c6caadd9f803a3adad5ab54ac65328c02d13295f40860cf33/testcontainers-4.8.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-14 03:50:19",
"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"
}