Skip to main content

# Kubernetes_WSGI

A wrapper for running your Python web application using Twisted in a way that works well for Kubernetes.

This also includes Prometheus metrics support.

## Quick Start

To install:

` pip install kubernetes-wsgi `

To launch your application:

` python -m kubernetes_wsgi myapp --port 8000 `

where myapp is an importable module name containing your WSGI application function.

## Why Threads?

The gold standard for Python WSGI servers is Gunicorn, renowned for its multi-process execution mode for effcient concurrency despite the dreaded Python GIL (Global Interpreter Lock). Unfortunately when working with containers, multi-process worker models can be difficult to work with as containers generally expect to only have a single process. Specifically this means if one of the forked workers is hit by an OOM and killed, the main process will simply restart it without triggering the usual metrics in Kubernetes for OOM’d Pods. Similarly we have a different way to handle multi-process concurrency in Kubernetes, through a Deployment with many replicas. In the simplest version would could use multiple replicas each handling only one request at a time, but using a thread pool improves throughput by taking advantage of the fact that most web applications are blocked on I/O most of the time (usually waiting for a response from a database or another web service).

## Why Twisted?

Gunicorn itself does have a threadpool mode, however it’s somewhat awkward to work with as it uses the futures ThreadPool implementation. Twisted’s ThreadPool is more efficent. This also allows installing the Prometheus metrics as a native Twisted web handler so it will work even if the threadpool is exhausted, meaning your metrics keep working even during a system overload.

Metadata

Release files for kubernetes-wsgi 1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kubernetes-wsgi 1.2
File Size Uploaded Provenance Actions
kubernetes_wsgi-1.2.tar.gz 11.7 kB Without provenance Details for kubernetes_wsgi-1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kubernetes-wsgi 1.2
File Interpreter ABI Platform Actions
kubernetes_wsgi-1.2-py3-none-any.whl Python 3 none any Details for kubernetes_wsgi-1.2-py3-none-any.whl

Total release size: 21.2 kB

Release files / kubernetes_wsgi-1.2.tar.gz

Download URL kubernetes_wsgi-1.2.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0576eaa9a7634fb8bab060571787e74a76fb7f61c56bc6f98f42453a9a7d45ee
BLAKE2b-256 checksum
How to use checksums
2fe959c46ddaf8144334e81657fb36b0df330416b1a74e4b90c8c73e79e95f92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.6.0 pkginfo/1.8.2 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.9.15

Release files / kubernetes_wsgi-1.2-py3-none-any.whl

Download URL kubernetes_wsgi-1.2-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c0254524e3e9d655aba0d403f8453e5f0660d3283ae81a299433f43c99faffd
BLAKE2b-256 checksum
How to use checksums
d533ab2fbf8552a46609a7cfbe56e23225e1b58816a5e0eafe0cec99ff330c90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.6.0 pkginfo/1.8.2 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.9.15

Security for kubernetes-wsgi 1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page