# 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.
## 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.7.0` | 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/96/3f/0ece1a2d55835771777d5899b3a51c301703f0e4ea2003dd4ebe7714e313/testcontainers-4.4.0.tar.gz",
"platform": null,
"description": "# 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## 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.7.0` | 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.4.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": "7d84f666d43653ff81e5f3fba622867cb6dcd463a9d626a050dbda9bd7a6afff",
"md5": "aabd75addbc8b5623241912937be7370",
"sha256": "455e0e28bbf9dcf2d66a342e3103b0d8889db3295a490c009a98848e08791837"
},
"downloads": -1,
"filename": "testcontainers-4.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "aabd75addbc8b5623241912937be7370",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 70070,
"upload_time": "2024-04-17T10:37:15",
"upload_time_iso_8601": "2024-04-17T10:37:15.673022Z",
"url": "https://files.pythonhosted.org/packages/7d/84/f666d43653ff81e5f3fba622867cb6dcd463a9d626a050dbda9bd7a6afff/testcontainers-4.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "963f0ece1a2d55835771777d5899b3a51c301703f0e4ea2003dd4ebe7714e313",
"md5": "fadff76a76a82c2dcb5b4f27cf7068a1",
"sha256": "f4e87c3831991f9b4d5b6544d0f438fbfd140a74c834b13efb15a2f7c89833c4"
},
"downloads": -1,
"filename": "testcontainers-4.4.0.tar.gz",
"has_sig": false,
"md5_digest": "fadff76a76a82c2dcb5b4f27cf7068a1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 41727,
"upload_time": "2024-04-17T10:37:18",
"upload_time_iso_8601": "2024-04-17T10:37:18.685680Z",
"url": "https://files.pythonhosted.org/packages/96/3f/0ece1a2d55835771777d5899b3a51c301703f0e4ea2003dd4ebe7714e313/testcontainers-4.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-17 10:37:18",
"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"
}