Vignettes
Python Package Manager
Python Packaging Manager is a nice write-up of the current state of Python packaging. On a detour, I spent time visiting Python Packaging Authority, and I didn't realize the number of libraries it envelopes, including flit, hatch, pipenv, et al. This is a nice thread describing what pypa is - not authoritative, but seems to be authoritative according to pep 609. pypa.io seems outdated, but the user guide is still content-rich. As an aside, Py-Pkgs is a nice read. A couple new libraries added to my backlog (pip-audit, rye)
Python Frameworks
- Python Frameworks Nice compendium of frameworks - so many unexplored - I highlighted a few I want to check out.
- Web Framework: Python-only web development (CubicWeb, Dara, Esmerald, FrappeFramework, Solara)
- API Development: async, graphql, less boilerplate (Litestar, strawberry, Graphene Python, Connexion)
- ML, DL, AI: The usual + AI (SuperAGI, mindsdb)
- Workflow & Pipelines: Data processing & task queues (Schedule, Mage, DoIt, kedro)
- Microservices: this category in this context is a bit new to me (Nameko, Falcon, minOS, gRPC)
- DevOps: utils and monitoring (SALT, Fabric)
- Web Crawling/Scraping: always useful when needed (Dude, Trafilatura)
- Gui & Tui: I haven't tried in many moons, time for another look (Eal, Gooey, Textual, Toga )
Snippets
structural patterns
def get_service_level(user_data: dict):
match user_data:
case {'subscription': _, 'msg_type': 'info'}:
return 'Service level = 0'
case {'subscription': 'free', 'msg_type': 'error'}:
return 'Service level = 1'
case {'subscription': 'premium', 'msg_type': 'error'}:
return 'Service level = 2'
def get_service_level(user_data: dict):
match user_data:
case {'subscription': _, 'msg_type': 'info'}:
return 'Service level = 0'
case {'subscription': 'free', 'msg_type': 'error'}:
return 'Service level = 1'
case {'subscription': 'premium', 'msg_type': 'error'}:
return 'Service level = 2'
Usage
@pytest.mark.parametrize('user_data, expected', [
({'subscription': 'free', 'msg_type': 'info'}, 0),
({'subscription': 'free', 'msg_type': 'error'}, 1),
({'subscription': 'premium', 'msg_type': 'error'}, 2),
])
def test_get_service_level(user_data, expected):
assert get_service_level(user_data) == expected
@pytest.mark.parametrize('user_data, expected', [
({'subscription': 'free', 'msg_type': 'info'}, 0),
({'subscription': 'free', 'msg_type': 'error'}, 1),
({'subscription': 'premium', 'msg_type': 'error'}, 2),
])
def test_get_service_level(user_data, expected):
assert get_service_level(user_data) == expected
safe pip install
Detailed opinion on pip install
python -m pip install --require-hashes --no-deps --only-binary :all: -r requirements.txt
Support view in the context of python -m usage
Support view in the context of dependency management.
Support view in the context of docs, src, and tests directories in the project root
.env file
Nice write-up .env file
GCP_PROJECT_ID=my-project-id
GCP_PROJECT_ID=my-project-id
import os
from dotenv import load_dotenv
load_dotenv()
GCP_PROJECT_ID=os.getenv('GCP_PROJECT_ID')
import os
from dotenv import load_dotenv
load_dotenv()
GCP_PROJECT_ID=os.getenv('GCP_PROJECT_ID')
data classes (slots=True)
Banish state-mutating methods from data classes offers practical advice but also motivates why with a breakdown of what is happening behind the scenes. One key takeaway was the penalty cost of setting (frozen=True). Here he provides a bit more details. Main point use (slots=True).