---
title: "docker | pypx"
description: "A Python library for the Docker Engine API."
canonical_url: "https://pypx.app/packages/docker"
meta:
  "og:description": "A Python library for the Docker Engine API."
  "og:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_docker%2Cversion_7.2.0%2Csummary_A%2BPython%2Blibrary%2Bfor%2Bthe%2BDocker%2BEngine%2BAPI.%2Clicense_Apache-2.0%2Cp_Ii9wYWNrYWdlcy9kb2NrZXIi%2Cs__PJYUDR9FZT5a3_q.png"
  "og:image:height": "630"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "docker 7.2.0"
  "twitter:image": "https://pypx.app/_og/d/h_630%2Cc_PackageCard%2Cname_docker%2Cversion_7.2.0%2Csummary_A%2BPython%2Blibrary%2Bfor%2Bthe%2BDocker%2BEngine%2BAPI.%2Clicense_Apache-2.0%2Cp_Ii9wYWNrYWdlcy9kb2NrZXIi%2Cs__PJYUDR9FZT5a3_q.png"
---

> Index of every page on this site: [llms.txt](https://pypx.app/llms.txt)

# **docker**

v7.2.0

A Python library for the Docker Engine API.

145 KB Python 3.8+ py3-none-anyApache-2.03 deps

[** Diff **](https://pypx.app/packages/docker/diff)

`$ uv add docker`

# Docker SDK for Python

[![Build Status](https://github.com/docker/docker-py/actions/workflows/ci.yml/badge.svg)](https://github.com/docker/docker-py/actions/workflows/ci.yml)

A Python library for the Docker Engine API. It lets you do anything the `docker` command does, but from within Python apps – run containers, manage containers, manage Swarms, etc.

## Installation

The latest stable version [is available on PyPI](https://pypi.python.org/pypi/docker/). Install with pip:

```
pip install docker
```

> Older versions (< 6.0) required installing `docker[tls]` for SSL/TLS support. This is no longer necessary and is a no-op, but is supported for backwards compatibility.

## Usage

Connect to Docker using the default socket or the configuration in your environment:

```
import docker
client = docker.from_env()
```

You can run containers:

```
>>> client.containers.run("ubuntu:latest", "echo hello world")
'hello world\n'
```

You can run containers in the background:

```
>>> client.containers.run("bfirsh/reticulate-splines", detach=True)
<Container '45e6d2de7c54'>
```

You can manage containers:

```
>>> client.containers.list()
[<Container '45e6d2de7c54'>, <Container 'db18e4f20eaa'>, ...]

>>> container = client.containers.get('45e6d2de7c54')

>>> container.attrs['Config']['Image']
"bfirsh/reticulate-splines"

>>> container.logs()
"Reticulating spline 1...\n"

>>> container.stop()
```

You can stream logs:

```
>>> for line in container.logs(stream=True):
...   print(line.strip())
Reticulating spline 2...
Reticulating spline 3...
...
```

You can manage images:

```
>>> client.images.pull('nginx')
<Image 'nginx'>

>>> client.images.list()
[<Image 'ubuntu'>, <Image 'nginx'>, ...]
```

[Read the full documentation](https://docker-py.readthedocs.io) to see everything you can do.

## **Details **

<dl>

<dt>Version</dt>
<dd>7.2.0</dd>

<dt>License</dt>
<dd>Apache-2.0</dd>

<dt>Python</dt>
<dd>&gt;=3.8</dd>

</dl>

## **Links**

- [Changelog](https://docker-py.readthedocs.io/en/stable/change-log.html)
- [Documentation](https://docker-py.readthedocs.io)
- [Homepage](https://github.com/docker/docker-py)
- [Source](https://github.com/docker/docker-py)
- [Tracker](https://github.com/docker/docker-py/issues)
- [View on PyPI](https://pypi.org/project/docker/)

## **Release Cadence **

**1**

releases in the past year

avg 55 days between releases

## **Maintainers **

- "Docker Inc." · [no-reply@docker.com](mailto:no-reply@docker.com)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://pypx.app/#website","@type":"WebSite","description":"The Python Package Index, reimagined. Fast search, dependency insights, download trends, and changelogs — all in one place.","name":"pypx","url":"https://pypx.app/"},{"@id":"https://pypx.app/packages/docker#webpage","@type":"WebPage","description":"A Python library for the Docker Engine API.","name":"docker","url":"https://pypx.app/packages/docker","isPartOf":{"@id":"https://pypx.app/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://pypx.app/packages/docker"]}]},{"@id":"https://pypx.app/packages/docker#/schema/software-application/1","@type":"SoftwareApplication","applicationCategory":"DeveloperApplication","description":"A Python library for the Docker Engine API.","license":"Apache-2.0","name":"docker","softwareVersion":"7.2.0"}]}
```

## Sitemap

See the full [sitemap](https://pypx.app/sitemap.md) for all pages.
