Writing Performant Python¶
Scientists, engineers, and professionals increasingly work with large, complex datasets and computational workflows. Effective analysis requires both understanding the data and writing code that uses time, memory, and hardware efficiently. This course introduces a practical workflow for writing performant Python: understand the problem, benchmark the code, profile bottlenecks, optimize the right parts, parallelize where appropriate, and use accelerators when they genuinely help.
Students will learn how Python executes code, why some programs become slow, and how to make evidence-based performance improvements. The course uses realistic examples to introduce benchmarking, profiling, algorithmic improvement, vectorized array programming, memory-aware computation, parallelization with Dask, and performance boosting with tools such as Cython, Numba, Pythran, Transonic, and Numexpr.
By the end of the course, participants will be able to diagnose performance problems, choose appropriate tools, and improve Python programs without sacrificing correctness, readability, or reproducibility.
Prerequisites
Basic experience with Python
Basic experience in working in a Linux-like terminal
Some prior experience in working with large or small datasets
Software setup
Episodes
Reference
Learning outcomes¶
This material is for all researchers and engineers who work with large or small datasets and who want to learn powerful tools and best practices for writing more performant, parallelised, robust and reproducible data analysis pipelines.
By the end of this module, learners should:
Explain common sources of Python performance bottlenecks.
Design and run reproducible benchmarks.
Use profiling tools to identify expensive functions, lines, and memory behavior.
Apply algorithmic, vectorization, memory-layout, and I/O improvements.
Use parallel and accelerated Python tools when they fit the workload.
Communicate performance tradeoffs clearly and keep optimized code reproducible.
Credit
Don’t forget to check out additional course materials from XXX. Please contact us if you want to reuse these course materials in your teaching. You can also join the XXX channel to share your experience and get more help from the community.
This course incorporates and adapts open training material from ENCCS/python-perf, ENCCS/hpda-python, ENCCS/word-count-hpda, coderefinery/word-count, CodeRefinery reproducible research, and HPC Carpentry Python material.
It also includes images and descriptions from lectures.scientific-python.org, Project Jupyter images under the BSD 3-Clause license, images from The Noun Project under CC-BY 3.0, and nbabel example code from https://github.com/paugier/nbabel under GPLv2.
License
CC BY-SA for media and pedagogical material
Copyright © 2025 XXX. This material is released by XXX under the Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0).
Canonical URL: https://creativecommons.org/licenses/by-sa/4.0/
You are free to
Share — copy and redistribute the material in any medium or format for any purpose, even commercially.
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
The licensor cannot revoke these freedoms as long as you follow the license terms.
Under the following terms
Attribution — You must give appropriate credit , provide a link to the license, and indicate if changes were made . You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
Notices
You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation .
No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material.
This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.
MIT for source code and code snippets
MIT License
Copyright (c) 2025, EVITA project, Ashwin Vishnu Mohanan, Claudia Blaas-Schenner, Jaison Lewis, Jasper Seehofer, Kevin Lüdemann, Kjartan Thor Wikfeldt, Mary Kate Chessey, Matthias Eulert, Tobias Haas, Victoria Döller, Yinyin Ma, and Yonglei Wang
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Note
To module authors: For code you may use any OSI-approved license as mentioned in https://spdx.org/licenses/, such as Apache License 2.0, GNU GPLv3, MIT. Please make sure to update the deed above and
LICENSE.code file accordingly.