About 149 results
https://rednafi.com/python/recipes-from-python-sqlite-docs/ · 11 Sep 2022
Practical SQLite recipes for Python: execute statements, batch operations, transactions, row factories, and context managers with sqlite3.
https://rednafi.com/python/use-urlsplit-over-urlparse/ · 10 Sep 2022
Use Python's urlsplit instead of urlparse for faster URL parsing by skipping the rarely-needed params component in URL decomposition.
https://rednafi.com/python/exitstack/ · 27 Aug 2022
Master Python's ExitStack for managing multiple context managers, conditional callbacks, request rollbacks, and avoiding nested with statements.
https://rednafi.com/python/compose-multiple-levels-of-pytest-fixtures/ · 21 Jul 2022
Combine session and function-scoped pytest fixtures to avoid expensive test setup while maintaining test isolation and preventing state coupling.
https://rednafi.com/python/patch-where-the-object-is-used/ · 18 Jul 2022
Master Python mocking: patch objects at their import location, not where they're defined, to avoid common unittest.mock pitfalls.
https://rednafi.com/python/partially-assert-callable-arguments/ · 17 Jul 2022
Assert specific mock call arguments while ignoring others using unittest.mock.ANY for flexible test assertions without brittle checks.
https://rednafi.com/python/apply-constraint-with-assert/ · 10 Jul 2022
Use Python assert statements to apply runtime constraints more succinctly than raising ValueError. Learn the trade-offs and best practices.
https://rednafi.com/python/stream-process-a-csv-file/ · 1 Jul 2022
Process large CSV files without OOM errors by streaming content line-by-line with HTTPX and concurrent.futures for parallel processing.
https://rednafi.com/python/django-bulk-operation-with-process-pool/ · 27 Jun 2022
Speed up Django bulk operations with ProcessPoolExecutor while preserving signals and hooks that bulk_create/bulk_update bypass.
https://rednafi.com/python/read-s3-file-in-memory/ · 26 Jun 2022
Download and process S3 CSV files in memory using boto3 and tempfile.NamedTemporaryFile without cluttering disk with temporary files.