docker-py

Official Python library for the Docker Engine API — manage containers, images, networks, and Swarm clusters from your own code.

SDK
PyPI
v7.2.0
7,221 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
83 /100 Excellent
Development Activity 68
Maintenance 72
Community 92
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
86 /100 Excellent
Architecture 85
Code Quality 78
Innovation 82
Learning Curve 100

Docker SDK for Python (published to PyPI as docker) is the official client library for the Docker Engine API, maintained by Docker Inc. It provides two complementary interfaces: a high-level, Pythonic object model (DockerClient) for everyday container, image, network, and volume operations, and a low-level APIClient that mirrors the full Docker Engine REST API for cases needing complete control.

The library handles the transport details of talking to a Docker daemon over a Unix socket, TCP, SSH, or Windows named pipe, plus TLS negotiation, streaming logs/attach sockets, and Swarm-mode orchestration (services, secrets, configs, nodes). It’s the library that powers higher-level developer tools and CI pipelines that need to drive Docker programmatically instead of shelling out to the docker CLI.

What You Get

  • High-level DockerClient object model for containers, images, networks, and volumes with Pythonic collections (client.containers.run(...), client.images.pull(...))
  • Low-level APIClient exposing the complete Docker Engine REST API for advanced or unsupported operations
  • Built-in transport support for Unix sockets, TCP, SSH (use_ssh_client), and Windows named pipes, plus TLS configuration via TLSConfig
  • Swarm-mode primitives — services, secrets, configs, and nodes — for managing multi-node Docker clusters
  • Streaming support for container logs, attach, and exec output via socket demuxing helpers

Common Use Cases

  • Programmatically building and running containers from CI/CD pipelines or test harnesses
  • Writing developer tooling (like Compose-style orchestrators) on top of the Docker Engine API
  • Automating image builds and pushes as part of a Python-based release process
  • Managing Swarm services, secrets, and configs from infrastructure automation scripts

Under The Hood

Architecture

docker-py splits its surface into two layers: a low-level APIClient (docker/api/client.py) built as a requests.Session subclass composed from a dozen *ApiMixin classes (build, container, image, network, volume, service, swarm, secret, config, plugin, exec, daemon) that each contribute one slice of the Docker Engine REST surface, and a high-level DockerClient (docker/client.py) that wraps an APIClient instance and exposes typed collections (ContainerCollection, ImageCollection, etc.) built on a shared Model/Collection base (docker/models/resource.py). Models are lazy, cached wrappers around the daemon’s raw JSON responses — reload() re-fetches attrs from the collection — so mutating operations like container.stop() delegate straight back down to the corresponding APIClient method. Transport selection (Unix socket, TCP, SSH, Windows named pipe) is resolved through pluggable HTTPAdapter subclasses (UnixHTTPAdapter, SSHHTTPAdapter, NpipeHTTPAdapter) registered onto the requests.Session, keeping the wire-transport concern fully decoupled from the API-mixin layer above it.

Tech Stack

The library targets Python 3.8+, uses requests and urllib3 as its sole hard HTTP dependencies, and builds with hatchling/hatch-vcs (version derived from git tags into docker/_version.py) rather than a hand-maintained version string. Optional extras are cleanly isolated: paramiko for SSH transport, websocket-client for a websocket-based attach mechanism, and pywin32 only on Windows. Linting is enforced with ruff, tests run under pytest with pytest-cov/pytest-timeout, and CI (GitHub Actions) runs lint plus unit and Docker-in-Docker integration jobs. Documentation is built with Sphinx and published to ReadTheDocs.

Code Quality

Test coverage is extensive — separate tests/unit and tests/integration suites (each several thousand lines) plus a dedicated tests/ssh suite, backed by fake_api_client/fake_api fixtures that stub Engine API responses for isolated unit testing. Error handling is centralized through a DockerException base class with specific subclasses (APIError, NotFound, ImageNotFound, BuildError, ContextNotFound, and others) rather than leaking raw requests exceptions, and create_api_error_from_http_exception maps HTTP status codes and response bodies to the right exception type. The codebase does not use static type hints or mypy, relying instead on docstrings and the extensive test suite for correctness; ruff enforces style consistency across both the library and its tests.

API Design The dual-client design is the standout ergonomic choice: newcomers can call docker.from_env() and immediately work with a Pythonic object model (client.containers.run(...), client.images.pull(...)), while power users who need Engine API parity drop to client.api (the underlying APIClient) without switching libraries. Naming closely mirrors the docker CLI and Engine API vocabulary (containers, images, networks, volumes, services, secrets, configs), which minimizes the mental translation for anyone who already knows Docker. Documentation is thorough — every public method carries a docstring covering parameters and examples, and the Sphinx docs on ReadTheDocs mirror the object model one-to-one — though the lack of type hints means IDEs can’t autocomplete method signatures as precisely as a typed alternative would.

Used by 20 apps in this directory

Python
100%
Apache 2.0

Agno

AI Development · Automation · Devops

42,874

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
66
Dependency
Built with
Python 100%
Updated yesterday
Python
48%
Other

Airbyte

Data Engineering · Developer Tools

22,260

Open-source ELT platform with 600+ connectors for moving data from any source to warehouses, lakes, and AI agents.

View details
95
Repo Health
80
Technical
64
Dependency
Built with
Python 48%
Kotlin 44%
Updated today
Python
87%
Apache 2.0

Apache Airflow

Data Engineering

47,268

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
64
Dependency
Built with
Python 87%
Updated today
Python
56%
Other

authentik

Authentication · Security

26,076

The self-hosted Identity Provider that replaces Okta, Auth0, and Entra ID with a unified SSO platform supporting SAML, OAuth2/OIDC, LDAP, RADIUS, and WebAuthn.

View details
92
Repo Health
81
Technical
66
Dependency
Built with
Python 56%
TypeScript 35%
Updated yesterday
Python
97%
MIT

auto-news

AI Assistants · Productivity

910

An AI-powered personal news aggregator that filters multi-source feeds through LLMs and delivers curated, noise-free summaries to your Notion workspace.

View details
43
Repo Health
53
Technical
67
Dependency
Built with
Python 97%
Updated 1 years ago
Python
62%
MIT

AutoGen

AI Development · Automation

61,546

Build autonomous and human-in-the-loop multi-agent AI systems with a layered, event-driven Python and .NET framework pioneered at Microsoft Research.

View details
68
Repo Health
78
Technical
71
Dependency
Built with
Python 62%
C# 25%
TypeScript 12%
Updated 1 weeks ago
Python
68%
Other

AutoGPT

AI Assistants · Automation · Productivity

187,722

Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.

View details
93
Repo Health
78
Technical
66
Dependency
Built with
Python 68%
TypeScript 30%
Updated today
C++
68%
Apache 2.0

ClickHouse

Analytics · Data Engineering · Databases

50,569

Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.

View details
95
Repo Health
90
Technical
65
Dependency
Built with
C++ 68%
Python 13%
Updated today
Python
66%
MIT

Flowfile

Data Engineering

398

Visual ETL that compiles to Polars — build pipelines on a canvas, export as standalone Python, and run anywhere without platform lock-in.

View details
83
Repo Health
81
Technical
66
Dependency
Built with
Python 66%
TypeScript 17%
Vue 16%
Updated yesterday

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers