legacy-cgi
Standalone fork of Python's removed standard-library cgi and cgitb modules.
Repository Health
Technical Analysis
legacy-cgi is a maintained fork of the cgi and cgitb modules that were removed from the Python standard library in Python 3.13 as part of PEP 594 (“dead batteries”). It packages those modules so existing CGI scripts continue to run unchanged on modern Python versions.
The project’s explicit goal is compatibility rather than new features: it preserves the historic API for parsing form data, handling file uploads, and rendering traceback pages so that legacy web scripts do not break when upgrading interpreters. New applications are pointed toward modern WSGI/ASGI frameworks instead.
What You Get
- The
cgimodule for parsing CGI form data, query strings, and multipart file uploads - The
cgitbmodule for rich, formatted traceback pages during CGI script debugging - A drop-in installation that lets existing CGI scripts run unmodified on Python 3.13+
- A recommended
python_version >= '3.13'install marker so it only activates where the built-ins are gone - A stability-focused maintenance policy prioritizing bug fixes over new features
Common Use Cases
- Keeping legacy CGI scripts alive when upgrading to Python 3.13 or later
- Providing the
cgi.FieldStorageAPI to old code without rewriting it for WSGI - Restoring
cgitbtraceback pages for debugging inherited CGI applications
Under The Hood
Architecture — The package is intentionally minimal: two top-level modules, cgi.py and cgitb.py, lifted from the CPython standard library, plus a cgi-bin/ example directory and packaging metadata. cgi.py centers on FieldStorage, which parses application/x-www-form-urlencoded and multipart/form-data request bodies from the CGI environment; cgitb.py formats uncaught exceptions into HTML or text traceback reports. There is no reimplementation — behavior mirrors the original modules exactly.
Tech Stack — Pure Python packaged with a modern pyproject.toml and a uv.lock. It has no third-party runtime dependencies and is meant to be installed with a python_version >= '3.13' environment marker so the built-in modules take precedence on older interpreters.
Code Quality — Because compatibility is the stated goal, changes are limited to bug fixes; a tests/ directory guards the preserved behavior. The code reflects its standard-library heritage rather than modern refactoring, which is deliberate for a drop-in replacement.
API Design — The API is exactly the historic cgi/cgitb surface (cgi.FieldStorage, cgitb.enable()), so developers migrating legacy scripts need learn nothing new — the value is precisely that the public interface is unchanged.