cog
Containers for machine learning
What it is and what it does
Cog is a CLI tool that abstracts away the complexity of containerizing machine learning models for production deployment. You define your model environment and inference logic in simple YAML and Python files, and Cog generates a Docker image with all the best practices baked in: correct CUDA/cuDNN/PyTorch/TensorFlow combinations, efficient layer caching, sensible environment defaults, and automatic OpenAPI schema generation from your Python type hints.
The generated container includes a high-performance HTTP inference server that exposes your model's inputs and outputs as a REST API. You can run it locally for testing, build it as a standalone Docker image for your own infrastructure, or deploy directly to Replicate. Cog handles the glue between research code and production deployment, eliminating the need for researchers to write Dockerfiles or coordinate with engineers on CUDA compatibility.
Use it for:
- Package a PyTorch or TensorFlow model with GPU support and deploy it as a REST API without writing a Dockerfile.
- Generate an OpenAPI schema and HTTP server from Python type annotations to serve inference requests.
- Resolve CUDA/cuDNN/framework version conflicts automatically instead of debugging dependency hell manually.
- Test a containerized model locally with `cog run` before building and shipping the Docker image.
- Deploy the same model container to your own Kubernetes cluster or to Replicate's hosted platform.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Cog packages machine learning models into production-ready Docker containers with automatic CUDA/dependency resolution, OpenAPI schema generation, and a built-in HTTP inference server.
Yes, if you are packaging ML models for production and want to avoid Dockerfile complexity and CUDA version mismatches. Cog is actively maintained, has low install friction, permissive licensing, and no known vulnerabilities. The main prerequisite is Docker; if you already have it, Cog is a straightforward way to standardize model containerization. Not necessary if you are building inference servers manually or using a higher-level ML platform that handles containerization for you.
Install
cog on PyPI
pip
pip install coguv
uv add cogpoetry
poetry add cogInstalling cog
Before you install
Low install friction with a pure-Python wheel. The package is actively maintained with a recent release and 9458 GitHub stars. It requires Docker as a system dependency, which is the primary prerequisite for use rather than a Python-level friction point.
License in practice
Apache License 2.0 is permissive; you can use, modify, and redistribute Cog and derivative works freely provided you include license notices and state changes. No commercial restrictions.
Quickstart
# Install Cog (requires Docker)
pip install cog
# Create cog.yaml and run.py, then:
from cog import BaseRunner, Input
class Runner(BaseRunner):
def run(self, text: str = Input()) -> str:
return f"Processed: {text}"
# Run locally
# cog run -i text="hello"
# Or build and serve
# cog build -t my-model
# cog serve
Docker must be installed and running. Cog is a CLI tool that orchestrates Docker; it does not run without it.
Verify before relying
- Whether coglet (a runtime dependency) is an internal Cog module or an external package with its own maintenance status.
- Performance characteristics of the auto-generated Rust/Axum HTTP server under load.
- Compatibility with GPU setups beyond NVIDIA (e.g., AMD ROCm, Apple Metal).
Package facts
| License | Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 5 — typing_extensions, pyyaml, structlog, requests, coglet |
| Maintenance | actively maintained — 0 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,146,426/month — #3,254 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: cog-0.22.0-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
sagemaker-serveProvides model serving and deployment…
permissive · top 5,000 on PyPI
tensorflow-serving-apiProvides Python client APIs to communicate with…
permissive · top 5,000 on PyPI
cogappCog executes Python code snippets embedded in…
permissive · top 15,000 on PyPI
sagemaker-containersProvides tools to build Docker containers…
permissive · top 15,000 on PyPI
docker-composeDocker Compose is a command-line tool for…
permissive · top 5,000 on PyPI
trussTruss is a CLI tool for packaging ML models…
permissive · top 5,000 on PyPI
tensorflowTensorFlow is an open-source machine learning…
permissive · top 5,000 on PyPI
sagemaker-trainingIntegrates training scripts into Docker…
permissive · top 15,000 on PyPI
prefect-dockerProvides Docker task execution and container…
permissive · top 5,000 on PyPI
replicateA Python client for running machine learning…
permissive · top 5,000 on PyPI