Topics covered in this episode:- Make Each Line Count, Keeping Things Simple in Python
- Parsel
- A Comprehensive Guide to Python Logging with Structlog
- Stamina
- Extras
- Joke
Watch on YouTube
About the show
Sponsored by Sentry: pythonbytes.fm/sentry
Connect with the hosts
- Michael: @mkennedy@fosstodon.org
- Brian: @brianokken@fosstodon.org
- Show: @pythonbytes@fosstodon.org
Join us on YouTube at pythonbytes.fm/live to be part of the audience. Usually Tuesdays at 11am PT. Older video versions available there too.
Brian #1: Make Each Line Count, Keeping Things Simple in Python
- Bob Belderbos
- Some great tips to help you simplify your Python code to make it more understandable and maintainable.
Michael #2: Parsel
- Parsel is a BSD-licensed Python library to extract data from HTML, JSON, and XML documents.
- Parsel lets you extract data from XML/HTML documents using XPath or CSS selectors.
- It supports:
- CSS and XPath expressions for HTML and XML documents
- JMESPath expressions for JSON documents
- Regular expressions
# Want a RSS feed detail from a website standard HTML?
selector = parsel.Selector(text=html_text)
for link in selector.css('head > link'):
rel = link.xpath('.//@rel').get()
rel_type = link.xpath('.//@type').get()
href = link.xpath('.//@href').get()
Brian #3: A Comprehensive Guide to Python Logging with Structlog
- Stanley Ulili
- structlog is an awesome logging tool, and already has great documentation.
- However, this article is a great starting point, highlighting:
- how easy it is to get started using structlog
- configuring the default log level
- changing the formatting
- customizing the time stamp
- adding custom fields
- adding contextual data
- filtering
- async
- …
Michael #4: Stamina
- via Matthias Bach, by Hynek
- Production-grade Retries Made Easy
- stamina is an opinionated wrapper around the great-but-unopinionated Tenacity package. Its goal is to be as ergonomic as possible, while doing the right thing by default, while minimizing potential for misuse.
- General additions on top of Tenacity
- Retry only on certain exceptions.
- Exponential backoff with jitter between retries.
- Limit the number of retries and total time.
- Automatic async support.
- Preserve type hints of the decorated callable.
- Count (Prometheus) and log (structlog) retries with basic metadata, if they’re installed.
- Easy global deactivation for testing.
Extras
Brian:
- The “pytest fixtures” chapter of the pytest course is available now.
- Also, the PYTHONBYTES 20% discount still active for bundle through the end of August.
Michael:
- Python 3.12.0 release candidate 1 released
- PyCon UK: The conference takes place from the 22nd to the 25th of September in Cardiff, Wales. The schedule is available at 2023.pyconuk.org/schedule/ and tickets are available at 2023.pyconuk.org/tickets/.
- PyData Eindhoven 2023, Nov 30 CFP open
- PyData Seattle Language Creators Charity Fundraiser: Adele Goldberg - Smalltalk, Guido Van Rossum, Anders Hejlsberg, C#, and James Gosling - Java. September 19, 2023: 12:00 - 4:00 PM, in person only.
Joke:
- Librarian
- chatgpt-failures