Python PyCache, NiceGUI, Flask-ngrok, and Async Tips
Python Development News
Managing pycache Folders
• A common frustration for Python developers is the proliferation of __pycache__ folders throughout project source trees.
• The environment variable PYTHONPYCACHEPREFIX allows developers to redirect all compiled *.pyc files to a single, centralized directory.
• This practice keeps source repositories clean, especially when zipping or sharing code, and prevents unnecessary clutter in the file system.
Building UIs with NiceGUI
• NiceGUI offers a modern, Python-based approach to creating user interfaces served through a web browser.
• Features include intuitive buttons, dialogues, markdown support, 3D plots, and interactive elements like knobs and joysticks.
• It is highly recommended for creating internal dashboards, robotics control panels, or quick micro-web applications due to its extensive documentation and ready-to-use examples.
Tools and Techniques
Flask-ngrok for Development
• Ngrok is a vital tool for exposing local servers to the public internet, which is indispensable for testing webhooks, APIs, and mobile app integrations.
• The flask-ngrok package simplifies this process by automating the tunnel creation whenever the Flask application starts, eliminating manual setup for local development.
Handling Async in Python
• The concept of No Async or Async-Optional libraries is gaining traction, exemplified by the Textual library.
• The "await me maybe" pattern, inspired by Simon Willison, allows developers to handle functions that could be either synchronous or asynchronous without forcing the entire stack to be async aware.
• This approach addresses the complexity of event loop management and makes Python's asynchronous model more accessible to legacy or simpler codebases.
Community and Humor
Documentation Mysteries
• Pytest-cov contains a peculiar cov fixture that provides low-level access to coverage data, humorously described as a "foot-gun" that some developers feel should be left alone to maintain the "mystery" of the codebase.
The Future of Legacy Code
"Surely no one, everyone will recognize how flexible and useful this architecture is, spend a huge amount of effort painstakingly preserving and updating this garbage I wrote in 20 minutes."
• A recent XKCD comic highlighted the irony of over-architecting code for future-proofing versus the reality of quick, hacky solutions that often end up providing the longest-lasting utility.