If you are a medical physicist drowning in repetitive manual QA tasks, Pylinac is the open‑source magic wand you have been waiting for. This Python library, built specifically for the medical physics community, automates the analysis of images from linear accelerators, CT simulators, and other devices – all with fewer than ten lines of code. In this guide, we will walk you through what Pylinac is, where to find it, how to install it, and how to write your first automated QA script. You do not need to be a coding expert; we will go step by step.
What Is Pylinac?
Pylinac is a pure‑Python library designed to perform quality assurance tasks as defined by TG‑142 and other relevant protocols. It can automatically analyze EPID images, star‑shot films, CT‑to‑density phantoms, and more. Because it was created by a medical physicist (Dr. James R. Kerns) and published in the Journal of Open Source Software, it has both clinical and academic acceptance. The real power: with a handful of commands you can load your image, run the analysis, generate a detailed PDF report, and move on – all in seconds.
Understanding GitHub and the Repository
Before you can use Pylinac, you need to know where it lives. The source code is hosted on GitHub. Do not let the technical jargon scare you. A repository is simply a master folder that contains all the project files, including code, documentation, and previous versions. The README is the front page of that repository – it gives you a quick overview, features, and basic installation instructions. Finally, a pull request is how anyone in the world can contribute improvements or bug fixes. Open‑source thrives on collaboration.
Documentation: Your Best Friend
While GitHub holds the code, the official documentation (hosted on Read the Docs) teaches you how to use it. For a medical physicist, the docs are your best resource. They contain four essential sections:
- Installation – how to set up Pylinac on your machine.
- User Guide – detailed explanations of each QA test (MLC, Winston‑Lutz, starshot, etc.).
- Examples – complete scripts you can adapt immediately.
- API Reference – full technical details of every function.
Start with the Examples section; looking at real scripts will make everything click.
Installing Pylinac
Installation is wonderfully simple. Open your terminal (command prompt on Windows) and type:
pip install pylinac
Press Enter. That is it. The Python package manager pip will automatically download Pylinac and all its dependencies. You are now ready to run your first automated QA script.
Your First Script: MLC Positioning QA
Let us automate a common daily or weekly test: MLC positioning using an EPID image. Write the following script in any text editor or Python IDE:
from pylinac import MLC
# 1. Load your EPID DICOM image
mlc = MLC(r"C:\path\to\your\epid_image.dcm")
# 2. Run the analysis
mlc.analyze()
# 3. Display the results
mlc.plot()
# 4. Generate a PDF report
mlc.publish_pdf("mlc_report.pdf")
That is it. In four lines you have performed a complete MLC analysis. The results include:
- Maximum leaf error
- Median leaf error
- Passing tolerance (percentage of leaves within specification)
- Error histogram showing the distribution of leaf positions
This automated analysis can detect small drifts before they become clinical problems, and it frees up your time for research or patient‑specific work.
Best Practices and Safety Tips
Automation is powerful, but it must be used wisely. Follow these guidelines:
- Always verify image orientation – a simple misalignment can produce misleading results.
- Use appropriate tolerance values – match your clinic’s protocols (e.g., 1 mm for MLC leaf position).
- Visually inspect the overlay – Pylinac will show the analyzed leaf edges overlaid on the image. Look at it with your own eyes.
- Cross‑validate with your existing QA software – run the same test both ways for a few weeks to ensure consistency.
Remember: algorithms are not perfect. Trust but verify.
Conclusion
Pylinac turns the boring, time‑consuming manual QA into a few seconds of automated code. Imagine the hours you can reclaim every week – time you can invest in deeper research, advanced dosimetry, or simply taking a break. Start today: open a terminal, install Pylinac, and run your first script. You will be amazed at how easy it is. Thank you for reading, and I hope you find this tool as liberating as I do.
🔍 Discover Kaptan Data Solutions — your partner for medical-physics data science & QA!
We're a French startup dedicated to building innovative web applications for medical physics, and quality assurance (QA).
Our mission: provide hospitals, cancer centers and dosimetry labs with powerful, intuitive and compliant tools that streamline beam-data acquisition, analysis and reporting.
🌐 Explore all our medical-physics services and tech updates
💻 Test our ready-to-use QA dashboards online
Our expertise covers:
🔬 Patient-specific dosimetry and image QA (EPID, portal dosimetry)
📈 Statistical Process Control (SPC) & anomaly detection for beam data
🤖 Automated QA workflows with n8n + AI agents (predictive maintenance)
📑 DICOM-RT / HL7 compliant reporting and audit trails
Leveraging advanced Python analytics and n8n orchestration, we help physicists automate routine QA, detect drifts early and generate regulatory-ready PDFs in one click.
Ready to boost treatment quality and uptime? Let’s discuss your linac challenges and design a tailor-made solution!
Get in touch to discuss your specific requirements and discover how our tailor-made solutions can help you unlock the value of your data, make informed decisions, and boost operational performance!

Comments