Skip to main content

Detect if your Python process is running inside a container. Supports Docker, Podman, Kubernetes, containerd, LXC, and more. Inspired by the popular is-inside-container npm package. Supports cached results with optional refresh.

Project description

Container Detect

Python Version License Tests PyPI PyPI Downloads

Detect if your Python process is running inside a container. Supports Docker, Podman, Kubernetes, containerd, LXC, and more. Inspired by the popular is-inside-container npm package. Supports cached results with optional refresh.

Features

  • Fast and reliable container detection for multiple container types
  • Supports Docker, Podman, Kubernetes, containerd, LXC, and more
  • Multiple detection methods for robustness
  • Cached results for performance optimization
  • Zero dependencies, minimal overhead
  • Type hints for better IDE support
  • Graceful error handling

Supported Container Types

  • Docker - Classic Docker containers
  • Podman - Podman containers
  • Kubernetes - Kubernetes pods
  • containerd - containerd containers
  • LXC - Linux Containers
  • CRI-O - Container Runtime Interface
  • AWS ECS - Amazon Elastic Container Service
  • And more container runtimes

Installation

pip install container-detect

Or using uv:

uv add container-detect

Usage

Check if running inside a container

from container_detect import is_inside_container

if is_inside_container():
    print("Running inside a container")
else:
    print("Not running inside a container")

Force refresh cache

from container_detect import is_inside_container

# Use cached result (default)
is_inside_container()  # Fast, uses cache

# Force a fresh check, bypassing cache
is_inside_container(force_refresh=True)  # Performs new detection

Credits

This package is inspired by the is-inside-container (npm) npm package by Sindre Sorhus.

Changelog

See CHANGELOG.md for a detailed list of changes and version history.

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct, development setup, and the process for submitting pull requests.

Support

If you find this library useful, please consider:

  • Starring the repository on GitHub to help others discover it.
  • 💖 Sponsoring to support ongoing maintenance and development.

Become a Sponsor on GitHub | Support on Patreon

License

MIT License - see LICENSE file for details.

Author

Y. Siva Sai Krishna

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

container_detect-1.0.0.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

container_detect-1.0.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file container_detect-1.0.0.tar.gz.

File metadata

  • Download URL: container_detect-1.0.0.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for container_detect-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2dc4ed70dcc6aabac32a568d2ff9d508f8d5391c9af1b77fbec7083d86d4a878
MD5 8e481fa2b5d3924b42f08b3cf66b9185
BLAKE2b-256 2deba7550d3557bb6ea4aefe57fff4c5d8a7572fbe05d0dc4b68797e6d9819c9

See more details on using hashes here.

File details

Details for the file container_detect-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: container_detect-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for container_detect-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dac566c42b22500cfd4db47b35bcc53433b37985bb27fb0b6abcb4e901175c96
MD5 c9a98116b70a25480dfb571c22c6b752
BLAKE2b-256 9b535e60520e1220ea5131aaf680b8d50193713df8825ad36014373bd7f3c95a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page