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,217 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
82 /100 Excellent
Development Activity 64
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

TypeScript
53%
Apache 2.0

Flowsint

Automation · Developer Tools

9,587

A privacy-first, graph-based OSINT investigation platform with 30+ automated enrichers for mapping relationships between domains, IPs, people, and organizations.

View details
85
Repo Health
71
Technical
67
Dependency
Built with
TypeScript 53%
Python 45%
Updated 2 weeks ago
Python
59%
Apache 2.0

MLflow

AI Development · Monitoring

28,331

The open source AI engineering platform for debugging, evaluating, monitoring, and optimizing production LLMs and agents at scale.

View details
96
Repo Health
86
Technical
66
Dependency
Built with
Python 59%
TypeScript 33%
Updated 1 weeks ago
Python
37%
Other

Open WebUI

AI Agents · AI Assistants

154,169

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
92
Repo Health
75
Technical
66
Dependency
Built with
Python 37%
Svelte 34%
JavaScript 21%
Updated 2 weeks ago
TypeScript
93%
Other

OpenHands

AI Code Assistants · AI Development

90,429

The self-hosted developer control center for running AI coding agents — locally, in Docker, on VMs, or across cloud backends — with automation workflows for GitHub, Slack, and more.

View details
91
Repo Health
82
Technical
67
Dependency
Built with
TypeScript 93%
Updated 1 weeks ago
Python
38%
Apache 2.0

OpenSandbox

Developer Tools · Security

15,761

Secure, fast, and extensible sandbox runtime for AI agents with multi-language SDKs and Docker/Kubernetes runtimes.

View details
85
Repo Health
81
Technical
70
Dependency
Built with
Python 38%
Go 37%
Updated 1 weeks ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

40,208

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 1 weeks ago
TypeScript
98%
MIT

Promptfoo

AI Development

25,857

An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.

View details
90
Repo Health
73
Technical
67
Dependency
Built with
TypeScript 98%
Updated 1 weeks ago
Rust
89%
Apache 2.0

Qdrant

AI Development · Databases · Search

34,991

Open-source vector database and search engine built in Rust for production-grade AI applications — from semantic search to RAG pipelines and recommendation systems.

View details
92
Repo Health
87
Technical
62
Dependency
Built with
Rust 89%
Updated 2 weeks ago
Python
99%
Apache 2.0

Rasa Open Source

AI Assistants · AI Development · Voice AI

21,345

Rasa Open Source is a Python machine learning framework for building contextual, multi-turn chatbots and voice assistants that understand natural language and maintain conversation state.

View details
63
Repo Health
78
Technical
63
Dependency
Built with
Python 99%
Updated 3 months ago

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