Registry / http-networking / legacy-cgi

legacy-cgi

JSON →
library2.6.4pypypi✓ verified 24d ago

legacy-cgi is a fork of the standard library `cgi` and `cgitb` modules, which were removed from Python's standard library in version 3.13 as per PEP 594. Its primary purpose is to provide a drop-in replacement to support existing CGI scripts and applications that rely on these modules, ensuring compatibility for Python 3.13+. The current version is 2.6.4, with development focused on maintaining compatibility and applying bug fixes rather than introducing new features.

pip install 'legacy-cgi; python_version >= "3.13"'
INSTALL
IMPORT
SIG · LEGACY-CGI
L
legacy-cgi
http-networkingpythonv2.6.4
Install
1.5s avg
Import
86ms
Disk
48MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.6.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.087s · 65.4MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.5s · import 0.085s · 18MB
48MB installed
● package 48MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cgi
import cgi
cgitb
import cgitb

This example demonstrates a basic CGI script that processes form data using `cgi.FieldStorage`. To run this, save the code as a `.py` file (e.g., `my_cgi_script.py`), make it executable (`chmod +x my_cgi_script.py`), and place it in your web server's configured CGI directory (e.g., `cgi-bin`). The script prints HTTP headers followed by HTML content to the standard output, which the web server then sends to the client.

# Save this as 'my_cgi_script.py' in your web server's cgi-bin directory # and ensure it's executable (e.g., chmod +x my_cgi_script.py) import cgi import cgitb import os # Enable traceback manager for CGI scripts (useful for debugging) # In a production environment, consider logging errors instead of displaying them. cgitb.enable() print("Content-Type: text/html") print() # Empty line signifies end of HTTP headers print("<!DOCTYPE html>") print("<html>") print("<head><title>Legacy CGI Example</title></head>") print("<body>") print("<h1>Simple CGI Form</h1>") form = cgi.FieldStorage() name = form.getvalue("name", "Guest") message = form.getvalue("message", "No message provided.") if form.getvalue("submit"): print(f"<p>Hello, <strong>{name}</strong>!</p>") print(f"<p>Your message: <em>{message}</em></p>") else: print("<p>Please fill out the form:</p>") print('<form method="post" action="my_cgi_script.py">') print(' <label for="name">Name:</label><br>') print(' <input type="text" id="name" name="name" value=""><br><br>') print(' <label for="message">Message:</label><br>') print(' <textarea id="message" name="message" rows="4" cols="50"></textarea><br><br>') print(' <input type="submit" name="submit" value="Submit">') print('</form>') print("</body>") print("</html>")
Debug
Known issues
breakingThe `cgi` and `cgitb` modules were entirely removed from the Python standard library in Python 3.13, following deprecation in Python 3.11 (PEP 594). Code relying on these modules will break without `legacy-cgi` installed on Python 3.13+ environments.
fix
Install `legacy-cgi` using `pip install legacy-cgi`. For optimal management, use a conditional dependency like `legacy-cgi; python_version >= "3.13"` in your `requirements.txt` or `pyproject.toml`.
affects: Python >= 3.13
gotchaOn Python versions prior to 3.13 (e.g., 3.11, 3.12), the standard library's `cgi` module still exists and takes precedence. Installing `legacy-cgi` on these versions will not automatically replace the standard library module unless the import path is explicitly manipulated, and it will not silence `DeprecationWarning`s from the standard library module.
fix
The package is primarily for Python 3.13+. If you are on an older Python version and receive deprecation warnings, `legacy-cgi` is not the solution to silence them; you must either upgrade to 3.13+ or explicitly handle warnings.
affects: Python 3.8 - 3.12
deprecatedCGI (Common Gateway Interface) is considered a legacy technology for web development. Modern web applications should generally use contemporary WSGI (e.g., Flask, Django) or ASGI (e.g., FastAPI) frameworks, which offer significantly better performance, security, and development features. CGI typically launches a new Python process for each request, leading to high overhead.
fix
For new projects, explore modern Python web frameworks like Flask, Django, or FastAPI. This library is intended for maintaining existing CGI-based applications.
affects: All versions (general architectural advice)
gotchaThe `legacy-cgi` project aims for compatibility and bug fixes, not feature enhancements or major refactoring. Its API will closely mirror the final version of the `cgi` and `cgitb` modules found in Python 3.12.
fix
Do not expect new features or significant architectural improvements within `legacy-cgi`. If advanced web capabilities are needed, migrate to a modern web framework.
affects: All versions
Upgrade
Version history
2.6.4latest on PyPI · released Oct 27, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Resources