On mod_python
29th August 2003
So, I’m getting stuck in to mod_python in a pretty big way at the moment. I’ve never even used mod_perl before, so coming from PHP this is turning out to be a real eye opener.
The key thing to realise about mod_python is that it gives you full control over the whole Apache request. Unlike PHP, you’re not writing scripts that just happen to use Apache as a go between—mod_python exposes a pretty big chunk of Apache’s internal API, and you are expected to hook straight in to it and start doing things. This certainly takes a while to get used to, but comes with some pretty big benefits. For one thing, your code is loaded once (well, once by each Apache process) and stays in memory. This means that global variables within your scripts persist between requests! Unfortunately, each Apache process (of which there are usually quite a few) has its own copy of the code so you can’t use this persistence ability for things like sessions, but it’s great for pooling database connections and keeping unchanging data such as templates in memory.
You can write your own handlers for the various parts of the Apache request. So far I’ve only been playing with the handler that serves up content, but it’s possible to do things like create a handler for the “Authentication” phase that authenticates users in some special way.
My biggest worry at the moment concerns the relative lack of documentation for mod_python on the web—the manual is pretty good, but other than that there’s precious little to get your teeth in to. Luckily the module has a reasonably high traffic mailing list which has so far answered all of the questions I’ve thrown at it promptly and in great detail. I hope to write more about mod_python as I become more comfortable with it. If anyone has any tips, I’d love to hear them.
More recent articles
- Weeknotes: Llama 3, AI for Data Journalism, llm-evals and datasette-secrets - 23rd April 2024
- Options for accessing Llama 3 from the terminal using LLM - 22nd April 2024
- AI for Data Journalism: demonstrating what we can do with this stuff right now - 17th April 2024
- Three major LLM releases in 24 hours (plus weeknotes) - 10th April 2024
- Building files-to-prompt entirely using Claude 3 Opus - 8th April 2024
- Running OCR against PDFs and images directly in your browser - 30th March 2024
- llm cmd undo last git commit - a new plugin for LLM - 26th March 2024
- Building and testing C extensions for SQLite with ChatGPT Code Interpreter - 23rd March 2024
- Claude and ChatGPT for ad-hoc sidequests - 22nd March 2024
- Weeknotes: the aftermath of NICAR - 16th March 2024