Internal Tooling with Python
How do I use Python to help maintain my projects?
by Jason Heflinger
Why Python?
Python as a language, I feel, has 2 ideals backing up its purpose: portability and prototyping. Although it can be used for so much more than that, these two aspects greatly complement what I'd like in an internal tool.

Python has AMAZING portability. It comes pre-installed on basically all modern machines, and functions cross-platform extremely well. This means that any Python internal tooling can be written and executed effectively everywhere! This makes it a great internal tooling candidate alone due to the fact that it is compatible with nearly all platforms and projects.

Although Python can be used for large scale products, at the end of the day, I consider Python a language that excels in prototyping. While it lacks in large scale efficiency, Python is perfect for quickly writing and implementing basic functionality. Because of this, it's perfect for writing internal tools quickly. After all, internal tools do not need to exactly be production level quality or efficiency, so all the downsides of using Python are negligible.
Project Analysis
One of the first internal tools I set up for every project is project analysis. With Python, it's incredibly easy to set up a basic parser on specific files in your project and determine basic information about them. For example, with a C project you can easily get any header files and source files, and then analyze them for things such as SLOC, types, functions, and more! This is often helpful to generalize the overview of your project, or just feel good about the progress you've made 😁. As long as you're analyzing strictly code files, the file content of most projects will be small enough for the parser to still run instantly despite being done in Python.
Build and Test Abstraction
One of the next things I set up in a project is an abstracted build/test tool! Since many of my projects have different or complex build systems, I tend to make an internal tool that lets me call ./build or ./test to automatically take care of any build or test details. I mainly do this so I only ever have to worry about running a few basic commands to build and debug a project, but it has come especially useful when working with others and introducing them to the development environment! This is also super easy to set up with Python, since Python can easily interact with the system shell, call third party executables, and easily manage files. Having this kind of internal tool helps me keep the project clean and portable!
Code Generation
Python is also great for code generation! Oftentimes it can be hard to organize a project without employing complex architecture. This is especially true when dealing with a language that lacks reflection, such as C or C++. For example, say you're creating a card game in C! You'd like to implement custom functionality for any possible card, so ideally you'd be able to get a card given its ID. However, this would be hard to keep organized, since every card you add would have to be modified and injected into something akin to a global switch statement. Not only that, if you plan to have each card to be in its own file so other developers can work without collision, you have to worry about also properly including them. Now you COULD just deal with it and make this ever so slightly complex process known to the dev team for whenever they want to add a card, but doing practices like that will eventually pile up and lead to complex project bloat and possible errors. Another option would be to integrate a complex reflection library and set it up so you can request a card by a given name, but that seems quite overkill, and depending on your usage could have significant overhead. So I propose the more-ideal solution of using a Python internal tool to automate the slightly complex process! With a little bit of scripting, it is trivial to make a tool that automatically creates a template card file and integrates it into the project seamlessly.
Final Words
Python has amazing qualities that benefit the purpose of internal tooling greatly. Even in professional environments, Python is commonplace for drafting up and proposing tooling and basic functionality, so why not use that for personal projects as well? Different tech stacks and project styles are always going to have their downsides, but sprinkling in the support of Python can usually absolve this quite easily!