Links
- Quora Discussion
- Automate the Boring Stuff with Python or book – a practical programming course for office workers, academics, and administrators who want to improve their productivity
- Learn Python The Hard Way, 3rd Edition.pdf
- 81 Python Code Snippets for Everyday Problems
- Jupyter Samples
- Should you choose Python over R?
Specific topics
- How to Use Generators and
yield
in Python, together withyield from
- Create pip-installable packagesCreate pip-installable packages
General
Packaging Python Projects
How to Package Your Python Code
Creating a pip installable package
[[Understand semantic versioning]]
Choose the right open-source licence
Github
Create your custom Python package that you can pip-install from your git repository
Poetry
Docs
When using Typer
How to Effortlessly Publish your Python Package to PyPI Using Poetry
It also helps with setup via poetry init
- Use virtual environments to develop Python codeUse virtual environments to develop Python code
What
I like to think of virtual environments as package bookshelves for each of my projects. If I’m working on a cooking project, there is no need for me to have a book on surfing.
Creates special isolated environments where all the packages and versions you install only apply to that specific environment. It’s like a private island! — but for code.
Why
Having only the packages I need on my “bookshelf” eliminates all chances for me to possibly experience gross global installation an...
Running remotely
- Colaboratory
- Colaboratory, or 'Colab' for short, allows you to write and execute Python in your browser with zero configuration required, free access to GPUs, and easy sharing.
- Kaggle
- Kaggle offers a no-setup, customizable, Jupyter Notebooks environment.
- Python Anywhere
- Host, run, and code Python in the cloud!
- Heroku
- Build data-driven apps with fully managed data services.
- Github Actions
- You can use Github Actions to run your Python on schedule.
- See this implementation for pulling data into CSVs.
- See my updated implementation
General tools
- shillelagh
- Making it easy to query APIs via SQL
- pythonji
- Write Python with emojis
- Pyscript
- Python in the browser – running directly on browser client through virtual machine
- Has some limitations over standard Python
- Slow but it's expected it will speed up
Data tools
- PyGWalker
- Tableau-style UI for visual data exploration
- Jupyter Notebooks in Excel
- Embed Jupyter into Microsoft Excel and write Python instead of VBA
- Neptyne
- Build powerful Spreadsheet apps in Python or bring Python to Google Sheets
- Python Graph Gallery
- This website displays hundreds of charts, always providing the reproducible code! It aims to showcase the awesome dataviz possibilities of Python.
- Python Data Visualization Libraries
- Ten Python dataviz libraries for any field.
- Polars
- Fast multi-threaded, hybrid-out-of-core query engine focussing on DataFrame front-ends
Snippets
- Find out available versions for
pip
package:pip install package==
- Check the list of packages installed, incl. their versions:
pip freeze
- Remove all packages that include a certain word:
pip list | grep "word" | cut -d ' ' -f1 | xargs sudo -H pip uninstall -y
- Pretty JSON in JupyterLab:
import json from IPython.display import JSON JSON(json.loads('{"map": 1}'))
- Remove accents:
from unidecode import unidecode def remove_accents(str): return unidecode(str)
- Generate passwords
import random import secrets import string def generate_password_simple(nbytes): # the password will be long 1.3x the size pw = secrets.token_urlsafe(nbytes) return pw def generate_password_custom(length, added): chars = string.ascii_letters + string.digits specs = ".+-*/=" main = [secrets.choice(chars) for i in range(length - added)] extra = [secrets.choice(specs) for i in range(added)] final = main + extra random.shuffle(final) pw = ''.join(final) return pw
Debugging
"Code does not do what you expect it to do, but what you tell it to do."
"The most effective debugging tool is still careful thought, coupled with judiciously placed print statements." – Brian Kernighan, Unix for Beginners
- List of tools:
- Time:
time
- Debugging:
pdb
- Static analysis:
mypy
orpyflakes
- Linting:
pycodestyle
orpylint
or evenblack
- Profiling:
cProfile
- Line-by-line profiling:
line_profiler
- Memory usage:
memory_profiler
- Visualisation:
pycallgraph
orFlameGraph
- Time:
- Read this chapter from The Missing Semester to find out more