Python Bytes is a weekly podcast hosted by Michael Kennedy and Brian Okken. The show is a short discussion on the headlines and noteworthy news in the Python, developer, and data science space.

#350 You've Got The Stamina For This Episode

August 29, 2023 00:30:55 29.87 MB Downloads: 0
Topics covered in this episode:
Watch on YouTube

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: