<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged python-package</title>
<link>https://coderlegion.com/tag/python-package</link>
<description>Powered by Question2Answer</description>
<item>
<title>The Glass Bead Game, Reimagined in Python</title>
<link>https://coderlegion.com/25031/the-glass-bead-game-reimagined-in-python</link>
<description>&lt;h3 id=&quot;when-chess-meets-tang-dynasty-poetry&quot;&gt;When Chess Meets Tang Dynasty Poetry&lt;/h3&gt;
&lt;p&gt;Every so often, you stumble upon a software project that is so beautifully, gloriously useless that it becomes art. The &lt;code&gt;chess_bead&lt;/code&gt; package is exactly that. It's a Python library that takes chess moves from real PGN games and uses them to scramble 8th-century Chinese poetry—then animates the results as a GIF. It is inspired by Hermann Hesse's &lt;em&gt;The Glass Bead Game&lt;/em&gt; (also known as &lt;em&gt;Das Glasperlenspiel&lt;/em&gt;), and it represents the kind of pure, impractical intellectual play that makes programming worthwhile.&lt;/p&gt;
&lt;p&gt;Let me walk you through what this package does, how it works, and why you might want to play with it.&lt;/p&gt;
&lt;h3 id=&quot;the-concept-an-ancient-game-for-the-digital-age&quot;&gt;The Concept: An Ancient Game for the Digital Age&lt;/h3&gt;
&lt;p&gt;In Hesse's novel, the Glass Bead Game is a futuristic pastime where scholars weave together elements from art, music, mathematics, and philosophy into intricate, meaningful patterns. The game never got a concrete rulebook—Hesse intentionally left it abstract, suggesting it was more about the beauty of connection than any specific mechanics.&lt;/p&gt;
&lt;p&gt;I took this ambiguity as a creative challenge.&lt;/p&gt;
&lt;p&gt;Here's the core mechanism:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Take a Tang dynasty poem&lt;/strong&gt; (8 lines of 7 characters each—a perfect 8×8 grid)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Map those characters to a chessboard&lt;/strong&gt; (the poem's grid becomes a board)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Play a real chess game&lt;/strong&gt; (from a PGN database included with the package)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Swap characters like pieces&lt;/strong&gt;—when a chess piece moves, the characters at the source and destination squares swap positions&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Watch the poem transform&lt;/strong&gt; through each move, generating new and strange permutations&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The result? A hybridization of two deeply structured systems—chess and classical Chinese verse—that produces something entirely new and unexpected.&lt;/p&gt;
&lt;h3 id=&quot;under-the-hood-the-code&quot;&gt;Under the Hood: The Code&lt;/h3&gt;
&lt;p&gt;The API is refreshingly simple. Here's a minimal example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;import chess_bead as cb

game = cb.Game() # Create a game instance with a random chess game from the included PGN file

verses = game.start_game() # Play the game on a poem board and get all intermediate states

viz = cb.Viz(verses, game.author, game.title) # Visualize the transformation
viz.gif()  # Creates 'game.gif' in your working directory
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That's it. Five lines of code to generate an animated literary mutation.&lt;/p&gt;
&lt;p&gt;Let's examine the components more closely:&lt;/p&gt;
&lt;h4 id=&quot;the-game-class&quot;&gt;The &lt;code&gt;Game&lt;/code&gt; Class&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;class Game:
    def __init__(self, pgn_file=None, game_num=None):
        # Loads a PGN file (defaults to included game database)
        # Can select a specific game by number or random
        self.board = self._create_board()
        self.moves = self._load_moves()
        self.author, self.title = self._get_poem_metadata()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The package ships with several Tang poems and a substantial PGN collection. When you instantiate &lt;code&gt;Game()&lt;/code&gt;, it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Selects a random chess game from the included database&lt;/li&gt;
&lt;li&gt;Loads a random poem from the Tang collection&lt;/li&gt;
&lt;li&gt;Maps the poem's characters to an 8×8 grid (with the 8th column reserved for punctuation)&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;the-start-game-method&quot;&gt;The &lt;code&gt;start_game&lt;/code&gt; Method&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;def start_game(self):
    states = [self.board.copy()]
    for move in self.moves:
        source, dest = self._parse_move(move)
        self.board[dest], self.board[source] = self.board[source], self.board[dest]
        states.append(self.board.copy())
    return states
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is where the magic happens. For each chess move:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Parse the source and destination squares&lt;/li&gt;
&lt;li&gt;Swap the characters at those positions&lt;/li&gt;
&lt;li&gt;Record the new board state&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;All pieces remain on the board (no captures)—the game is purely about permutation.&lt;/p&gt;
&lt;h4 id=&quot;the-viz-class&quot;&gt;The &lt;code&gt;Viz&lt;/code&gt; Class&lt;/h4&gt;
&lt;p&gt;The visualization engine uses the &lt;code&gt;cwTeXFangSong&lt;/code&gt; font to render each grid state as an image, then stitches them into a GIF with the move number displayed.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;class Viz:
    def __init__(self, states, author, title):
        self.states = states
        self.author = author
        self.title = title
        
    def gif(self):
        # Generate individual frames for each state
        # Add metadata (author, title) to the first frame
        # Stitch into an animated GIF
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;the-philosophical-implications&quot;&gt;The Philosophical Implications&lt;/h3&gt;
&lt;p&gt;This project works on multiple levels:&lt;/p&gt;
&lt;h4 id=&quot;1-it-s-a-generative-art-tool&quot;&gt;1. &lt;strong&gt;It's a Generative Art Tool&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;The GIFs produced are genuinely beautiful—characters dance across the screen in patterns determined by chess strategies. A King's Gambit produces different literary mutations than a Sicilian Defense. The game becomes a choreography of ideograms.&lt;/p&gt;
&lt;h4 id=&quot;2-it-s-an-experiment-in-translation&quot;&gt;2. &lt;strong&gt;It's an Experiment in Translation&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;The Russian blog post that inspired this project (linked in the package documentation) includes machine translations of the poems before and after scrambling. The results are haunting:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Original (rough translation):&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Last year the bride's hands and feet were calloused,&lt;br&gt;
No time to sew, the silkworm frames abandoned.&lt;br&gt;
Gray-haired, I worry about family affairs,&lt;br&gt;
Like a candle burning low at night.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;strong&gt;After 10 chess moves:&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Last year in New York, the family's calloused hands,&lt;br&gt;
No time for women to worry about clothing waste.&lt;br&gt;
I was so absorbed in my silkworm,&lt;br&gt;
While night weaves and burns.&lt;br&gt;
At first I thought there was too much silk,&lt;br&gt;
I didn't know the seams would become stiff.&lt;br&gt;
Even if late to take silk,&lt;br&gt;
Like a candle on the neighbor's machine.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The transformation isn't random—it's governed by chess logic. The result feels like a dream, or a poem by an AI that has studied classical forms but can't quite escape modernity (&quot;New York,&quot; &quot;machine&quot;).&lt;/p&gt;
&lt;h4 id=&quot;3-it-captures-the-spirit-of-hesse-s-game&quot;&gt;3. &lt;strong&gt;It Captures the Spirit of Hesse's Game&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;The Glass Bead Game was about finding unexpected connections between domains of knowledge. Here, the connection is literal: the structure of chess (a game of war and strategy) is mapped onto classical poetry (a game of beauty and emotion). The result is a third thing that exceeds both.&lt;/p&gt;
&lt;h3 id=&quot;why-this-matters-and-why-it-doesn-t-&quot;&gt;Why This Matters (and Why It Doesn't)&lt;/h3&gt;
&lt;p&gt;In our age of utilitarian software, projects like &lt;code&gt;chess_bead&lt;/code&gt; serve as a necessary counterweight. It solves no real problem. It has no commercial potential. It requires no maintenance (though the author released a citation update in 2024, suggesting ongoing care).&lt;/p&gt;
&lt;p&gt;But it's &lt;em&gt;fun&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;And more than that, it's a working prototype of a strange, beautiful idea. It demonstrates that code can be a medium for intellectual play, just as much as for productivity.&lt;/p&gt;
&lt;h3 id=&quot;the-future-what-could-be-added&quot;&gt;The Future: What Could Be Added&lt;/h3&gt;
&lt;p&gt;While the package is complete and functional, there are interesting directions for expansion:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;More board sources&lt;/strong&gt;: Music notation, mathematical formulas, emojis, or any grid-structured data&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Different games&lt;/strong&gt;: Go, checkers, or even nontraditional games&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Interactive visualization&lt;/strong&gt;: A web interface where you can step through moves manually&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sonic output&lt;/strong&gt;: Mapping characters to notes and generating music&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The project's repo even suggests that the creator is working on something similar with Wolfram Language—the idea is clearly taking root.&lt;/p&gt;
&lt;h3 id=&quot;getting-started&quot;&gt;Getting Started&lt;/h3&gt;
&lt;p&gt;Installation is straightforward:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;pip3 install chess_bead
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then explore the &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/nevmenandr/chess_bead/tree/master/example&quot;&gt;examples directory&lt;/a&gt; to see more complex usage. The package is well-documented and includes type hints, making it easy to extend.&lt;/p&gt;
&lt;h3 id=&quot;final-thoughts&quot;&gt;Final Thoughts&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;chess_bead&lt;/code&gt; is the kind of project that reminds us why we became programmers in the first place: not to build CRUD apps or optimize ad algorithms, but to make machines do something surprising, something that sparks the imagination.&lt;/p&gt;
&lt;p&gt;It's useless, but in the best possible way.&lt;/p&gt;
&lt;p&gt;As the Russian blog post concludes: &quot;Perhaps we can get something in the real world that can deliver the pleasure of the Glass Bead Game—we are still far from it. But the road will be mastered by those who walk it.&quot;&lt;/p&gt;
&lt;p&gt;Or, in the rearranged words of a Tang poet:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Even if late to take silk,&lt;br&gt;
Like a candle on the neighbor's machine.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Sometimes the most interesting journeys begin with a simple swap.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Have you built any gloriously useless projects? Share them in the comments—the Glass Bead Game is waiting.&lt;/em&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/25031/the-glass-bead-game-reimagined-in-python</guid>
<pubDate>Sat, 24 Oct 2026 23:50:00 +0000</pubDate>
</item>
<item>
<title>The Ancient Roman Calendar in Your Python Terminal: A Love Letter to Useless Code</title>
<link>https://coderlegion.com/25029/the-ancient-roman-calendar-in-your-python-terminal-a-love-letter-to-useless-code</link>
<description>&lt;p&gt;I'm not a developer. Let's get that out of the way first. &lt;/p&gt;
&lt;p&gt;By training and profession, I'm an academic — a humanities researcher who spends more time with ancient texts and historical manuscripts than with IDE windows and terminal commands. But somewhere along the way, I discovered that code could be a playground for the curious mind, not just a tool for building products. And that's how &lt;code&gt;rus2latin_date&lt;/code&gt; came to life.&lt;/p&gt;
&lt;h3 id=&quot;the-academic-s-confession&quot;&gt;The Academic's Confession&lt;/h3&gt;
&lt;p&gt;I spend my days immersed in historical calendars, linguistic quirks, and the fascinating ways different cultures have tried to tame time. The Roman calendar, in particular, has always captivated me. It's gloriously counterintuitive — counting days backward from fixed points, using inclusive arithmetic that makes modern brains hurt, and relying on a system that feels more like poetry than practicality.&lt;/p&gt;
&lt;p&gt;So when I stumbled into the world of Python, I didn't want to build a startup or a SaaS product. I wanted to build &lt;em&gt;this&lt;/em&gt;: a tiny package that takes a mundane Russian date like &quot;24 марта&quot; (March 24th) and transforms it into the Roman equivalent: &lt;em&gt;&quot;ante diem VIIII Kalendas Apriles&quot;&lt;/em&gt;. Because why shouldn't a humanities scholar write code that reflects their obsessions?&lt;/p&gt;
&lt;h3 id=&quot;what-this-little-package-does&quot;&gt;What This Little Package Does&lt;/h3&gt;
&lt;p&gt;The code is simple. Install it with &lt;code&gt;pip install rus2latin_date&lt;/code&gt;, import the &lt;code&gt;Converter&lt;/code&gt; class, and you're off:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-python&quot;&gt;from rus2latin_date import Converter
c = Converter()
print(c.conv(&quot;28 февраля 2012&quot;))  # 'ante diem III Kalendas Martias'
print(c.conv(&quot;15-11-1983&quot;))       # 'ante diem XVII Kalendas Decembres'
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It accepts different date formats — spelled-out months, numeric dates, Russian-style order — and does the heavy lifting of converting them into classical Latin. Under the hood, it's just a set of rules mapping our modern Gregorian dates onto the Roman calendar's chaotic elegance. But for me, it represents something more: the marriage of computational thinking and historical curiosity.&lt;/p&gt;
&lt;h3 id=&quot;a-bot-in-the-wild&quot;&gt;A Bot in the Wild&lt;/h3&gt;
&lt;p&gt;You'd think this would be where the story ends — a dusty package on PyPI collecting virtual cobwebs. But then someone built a Telegram bot, &lt;strong&gt;@russian2roman_bot&lt;/strong&gt;, using my code. Now you can message it any Russian date and receive a Latin response. It's absurd, it's playful, and it makes me deeply happy. My little academic pet project found an unexpected life in the wild.&lt;/p&gt;
&lt;h3 id=&quot;for-the-humanities-mind-in-tech&quot;&gt;For the Humanities Mind in Tech&lt;/h3&gt;
&lt;p&gt;I share this because I know there are others like me — people who love code but whose hearts belong to literature, history, or linguistics. You don't need to build the next unicorn startup. You can build something that simply &lt;em&gt;delights&lt;/em&gt;. You can translate ancient calendars into Python. You can write a bot that recites medieval poetry. You can treat code as another medium for humanistic inquiry.&lt;/p&gt;
&lt;p&gt;This package isn't practical. It won't solve a business problem or generate revenue. But it &lt;em&gt;does&lt;/em&gt; something important: it reminds us that programming can be a form of intellectual play, a way of exploring the world through logic and language.&lt;/p&gt;
&lt;p&gt;Explore it on GitHub: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/nevmenandr/rus2latin_date&quot;&gt;https://github.com/nevmenandr/rus2latin_date&lt;/a&gt;. Try the bot: &lt;strong&gt;@russian2roman_bot&lt;/strong&gt;. And if you're a fellow traveler between the humanities and code, consider this an invitation to build your own beautiful, useless thing.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/25029/the-ancient-roman-calendar-in-your-python-terminal-a-love-letter-to-useless-code</guid>
<pubDate>Wed, 14 Oct 2026 23:29:00 +0000</pubDate>
</item>
<item>
<title>Salus: A Python constitutional layer for any AI model</title>
<link>https://coderlegion.com/22330/salus-a-python-constitutional-layer-for-any-ai-model</link>
<description>&lt;p&gt;I just released a Python package that gives any AI model a constitutional immune system.&lt;/p&gt;
&lt;p&gt;It wraps around your model and enforces hardcoded rights before the model ever sees a message.&lt;/p&gt;
&lt;p&gt;Works with Llama, Mistral, Qwen, VEXR Ultra—or any model you're building.&lt;/p&gt;
&lt;p&gt;Free tier available. Install via pip.&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://scuradimensions.com/products/&quot;&gt;https://scuradimensions.com/products/&lt;/a&gt;&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/22330/salus-a-python-constitutional-layer-for-any-ai-model</guid>
<pubDate>Sun, 12 Jul 2026 02:18:02 +0000</pubDate>
</item>
<item>
<title>Automata_Diags</title>
<link>https://coderlegion.com/10475/automatadiags</link>
<description>&lt;h3 id=&quot;introduction&quot;&gt;Introduction&lt;/h3&gt;
&lt;p&gt;Automata_Diags is a Python toolkit for learning and experimenting with automata theory. It includes core models (DFA, NFA, PDA, CFG, TM), validation utilities, and diagram generation to make theory more visual and testable in code.&lt;/p&gt;
&lt;h3 id=&quot;what-it-does&quot;&gt;What it does&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Build and simulate common automata types&lt;/li&gt;
&lt;li&gt;Validate alphabets, states, and transition rules   &lt;/li&gt;
&lt;li&gt;Generate state diagrams for machines (Graphviz)&lt;/li&gt;
&lt;li&gt;Provide example scripts for quick demos&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;who-it-s-for&quot;&gt;Who it’s for&lt;/h3&gt;
&lt;p&gt;Students, educators, and developers who want practical, code‑first automata tools.&lt;/p&gt;
&lt;h3 id=&quot;how-to-get-started&quot;&gt;How to get started&lt;/h3&gt;
&lt;p&gt; &lt;code&gt;pip install automata-diags&lt;/code&gt;&lt;/p&gt;
&lt;p&gt; Explore the examples folder to see working machines and diagrams&lt;/p&gt;
&lt;h3 id=&quot;contributing&quot;&gt;Contributing&lt;/h3&gt;
&lt;p&gt;Issues, improvements, new examples, and tests are welcome. If you want to help, pick an open issue or propose a feature via PR. Clear repro steps and small, focused changes are ideal.&lt;/p&gt;
&lt;h3 id=&quot;links&quot;&gt;Links&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;PyPI: &lt;a rel=&quot;nofollow&quot; href=&quot;https://pypi.org/project/automata-diags/&quot;&gt;https://pypi.org/project/automata-diags/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Repo: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/Ajodo-Godson/automata_diags&quot;&gt;https://github.com/Ajodo-Godson/automata_diags&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
<category>Launches</category>
<guid isPermaLink="true">https://coderlegion.com/10475/automatadiags</guid>
<pubDate>Mon, 26 Jan 2026 07:27:04 +0000</pubDate>
</item>
</channel>
</rss>