Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book

#350: You've Got The Stamina For This Episode

Published Tue, Aug 29, 2023, recorded Tue, Aug 29, 2023
Watch this episode on YouTube
Play on YouTube
Watch the live stream replay

About the show

Sponsored by Sentry: pythonbytes.fm/sentry

Connect with the hosts

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:

Michael:

Joke:


Want to go deeper? Check our projects