Rewriting My Django Libraries, Years Later
I rewrote django-spellbook and django-mercury-performance from scratch. They're out now as dj-spellbook and dj-mercury, with a third package called spellbook-engine underneath, and Storm Developments maintains all three. This is why I started over instead of patching the old ones, and what I did differently the second time.
That row is a SpellBlock. Here's the source:
{~ shelf ~}
{~ package name="spellbook-engine" icon="/media/images/blog/django-rewrite/spellbook-engine.svg" href="https://git.stormdevelopments.ca/official-public/spellbook-engine" about="The syntax: finds SpellBlocks, refuses bad documents" /~}
{~ package name="dj-spellbook" icon="/media/images/blog/django-rewrite/dj-spellbook.svg" href="https://git.stormdevelopments.ca/official-public/dj-spellbook" about="The Django half: renders each block through a template" /~}
{~ package name="dj-mercury" icon="/media/images/blog/django-rewrite/dj-mercury.svg" href="https://git.stormdevelopments.ca/official-public/dj-mercury" about="Counts a test's database trips, fails it on a bug" /~}
{~~}
Two learning projects
I built the first versions as learning projects. Every idea I had went in, and most of them stayed in after I'd moved on from them. Both packages worked and people used them, but they carried a lot of experiments nobody needed, including me.

Years later I'm a much better programmer. I run my own software company, I operate the servers it runs on, and I think about systems in a way I didn't back then. Fixing the old code would have meant deleting most of it, so I started over.
The syntax and the rendering are separate now
The old django-spellbook found the blocks and rendered them, all in one Django package. The rewrite splits that in two.
spellbook-engine reads a document, finds the SpellBlocks in it and refuses a document the syntax forbids. It renders nothing. It's a Rust crate with no dependencies, and the Python module is built from the same code. dj-spellbook is the Django half. It sends the markdown through markdown-it-py and each block through a Django template.
The syntax has one definition now. The Django renderer uses it, and so does the small Rust program that builds django-spellbook.org. When the syntax changes, it changes in one place.
A parser that says no
The engine is strict on purpose. A document it can't read cleanly is refused with an error. My company's site checks every stored document against a new engine version before a deploy rolls, and if one is refused, the deploy stops and the old site keeps serving until I fix the document. I'd rather find a bad document at deploy time than on a live page.
Mercury
dj-mercury counts the trips to the database a Django test makes, and fails the test when the count is a bug. I wrote a whole post on it last week. My company's site never ran the old django-mercury-performance. It went straight to the rewrite, and the first test I wrapped failed, which is how I found a loop on the blog index.
Why Storm maintains them
The most annoying thing about Django libraries is maintenance. Before I add one to a project, I have to really look into who maintains it, when it was last released, and whether it'll keep up with Django's own release cycle. Good libraries fall behind all the time, and you find out when an upgrade breaks.
So these live under Storm Developments now. As long as Storm operates, they stay maintained and updated. My company's own site runs on them every day, so a broken release is something I'd hit before anyone else does.
I got the licence wrong first
I published them under AGPL-3.0, because that's what Garage uses, and Storm Buckets runs on Garage. A few days later I learned why that was a mistake for a library.
Garage is a program. You run it and talk to it over the S3 API, so the AGPL never reaches your code. A library gets imported into your application, and a lot of lawyers read AGPL on an import as covering the whole app. Some companies ban AGPL dependencies outright because of that reading.
So 0.2.0 is MPL-2.0. Your own code stays yours. If you change a file in one of these packages and distribute it, you share that file. Versions before 0.2.0 stay AGPL, since a licence can't be taken back from a release.
Contributing
The source lives on my company's Forgejo instance, the main home of the code. Signups there are closed for security, so issues and pull requests go to the GitHub mirrors. I read and reply to every one, and I'm happy to take features that fit the design goals.
A pull request doesn't get merged on GitHub. I apply the change on the forge with you credited as a co-author, and the mirror picks it up from there. Keeping the main copy on our own forge is the sovereignty principle Storm is built on. I'm also wary of GitHub. It's the biggest target there is, and I don't want it to be the only place my code lives.
Get them
pip install dj-spellbook
pip install dj-mercury
Both need Python 3.12 or newer and Django 5.2 or newer. Coming from the old packages, it's a fresh install under the new names, and in Mercury monitor is now performance_monitor. The docs are at django-spellbook.org, served from a Storm Bucket.
Have comments? Add me on Mastodon and shoot me a message.
Have comments? Add me on Mastodon and shoot me a message.