Learn Python with Talk Python's 270 hours of courses

Gatorade-powered Python APIs

Episode #324, published Fri, Jul 9, 2021, recorded Thu, Jul 8, 2021

Python is used to solve a large and varied set of problems. One of its core pillars is web APIs. Another one is ML and data science. Those two important pieces were brought together in an unexpected yet magically-futuristic way by Rod Senra's team working with the Gatorade Sports Science Institute.

They created a patch that you wear while working out once or twice. It analyzes your perspiration. Combines with it other factors like running distance, sleep quality, and more. Then provides recommendations, using Python, about how to get more effective fitness.

Watch this episode on YouTube
Play on YouTube
Watch the live stream version

Episode Deep Dive

Guest Introduction and Background

Rod Senra is a seasoned Python developer and Technology Director at Work & Co. Rod has been programming in Python since 1997 (starting with version 1.5.2!), using it across multiple continents and companies. His recent endeavor includes working closely with the Gatorade Sports Science Institute to build the Gatorade GX web API platform, where Python and web technologies converge with sports science and wearable tech.

What to Know If You're New to Python

If you're just getting started, here are a few key points from the episode to help you follow along:

  • Python can serve many roles, from web APIs (Flask) to data science (NumPy, Pandas) and even hardware integration.
  • Flask is a popular web framework that allows you to build simple and scalable APIs quickly.
  • Data manipulation and computations (like measuring sweat rates) often rely on Python’s numerical ecosystem (e.g., numpy, pandas).
  • Tools like pint (for unit conversions) and pendulum (for date-time handling) can make your code more accurate and easier to maintain.

Key Points and Takeaways

  1. Bringing Wearable Tech and Python Together
    The Gatorade GX project bridges sports-science wearables (a “sweat patch”) with Python-based data analysis and web APIs. Wearers scan the patch after workouts to measure sweat and sodium levels, and a backend Python service processes that data in real time for hydration and nutritional recommendations.

  2. Building a Versatile API for Fitness Data
    Rod and team aggregated athlete workout data from Strava, Garmin, and HealthKit into one timeline. From there, the Python backend (Flask) combines it with sweat patch data to deliver personalized advice. This “glue” approach shows Python's flexibility in orchestrating complex multi-service platforms.

  3. Monolith vs. Microservices in a Small Team
    Initially, the project considered splitting into microservices (e.g., Flask plus Quart for async tasks). But with only four or five developers, maintaining separate services became a burden. Consolidating into a single “monolith” Flask application simplified development and worked well under real-world deadlines.

  4. Pivoting from Azure Cosmos DB to MongoDB
    Due to organizational changes, the backend switched from Azure Cosmos DB to MongoDB Atlas. MongoDB’s flexible document model and easy transitions across cloud vendors reduced friction. This proved that a NoSQL approach could adapt quickly to shifting project requirements.

  5. Performance Considerations: Fast Enough Is Enough
    Python sometimes raises questions about performance, but Rod emphasizes that real bottlenecks are often I/O or complex logic. The Gatorade GX team used caching and efficient algorithms rather than rewriting in a “faster” language. Python was “fast enough” for the required workload.

  6. Leveraging Pint for Unit Conversion
    Handling sweat rate, fluid volume, and electrolyte concentrations demands accurate unit conversions. The team used pint, which transparently manages units (e.g., meters vs. inches) and drastically cuts down errors.

  7. Handling Time Zones with Pendulum
    Fitness data arrives in various time zones, making correct date-time calculations essential. Instead of raw Python datetime plus manual zone conversions, they used pendulum for an ergonomic, error-resistant approach that inherits from Python’s built-in datetime system.

  8. Combining Machine Learning & Statistical Models
    To interpret sweat patch data, the platform applies GSSI research and statistical modeling in Python. By combining local patch readings, user parameters (weight, sport type, environment), and historical data, the API estimates future sweat rate and fluid loss—minimizing repeated patch usage.

  9. Constraint-based Optimization with Python
    For nutritional recommendations, the team used python-constraint to juggle carbs, proteins, and electrolytes across possible product combinations. This discrete constraint solver automatically navigates an otherwise tedious search space.

  10. Maintenance-Driven Development
    Rod stresses that rewriting and refactoring is natural as real-world understanding grows. Knowing they’d maintain this code long-term, the team preferred an easy-to-extend approach (Flask monolith, NoSQL) over a more “trendy” but complex microservice architecture. Keep it “boring,” stable, and maintainable.

Interesting Quotes and Stories

"Python was the one thing that stuck with me since 1997 across different companies, two different continents. But Python was the one thing that remained the same."
— Rod Senra

"When your success measurement is considering the maintenance phase, the long-term success of the project, the mindset is a different one. It's about stability... It's about writing robust code coverage."
— Rod Senra

"If you have five developers, microservices can become a nightmare really fast. The overhead doesn't pay off."
— Rod Senra

Key Definitions and Terms

  • NoSQL (Non-Relational Database): A flexible approach to data storage that typically uses JSON-like documents instead of relational tables. Examples: MongoDB, Cosmos DB.
  • Constraint Problem Solving: A computational method that explores possible value assignments that satisfy a set of conditions.
  • Pint: A Python library for managing units and dimensional analysis, ensuring consistent conversions.
  • Pendulum: A time library built on datetime, helping with time zones and date arithmetic more cleanly.

Learning Resources

Here are some courses to help you deepen your Python skills:

Overall Takeaway

In this episode, we see how a single Python-based backend can unify cutting-edge hardware (the Gatorade sweat patch), external fitness APIs (Strava, Garmin, Apple HealthKit), and advanced data-science calculations (for hydration insights). Rod’s project underscores that “fast enough is enough,” that monoliths can work beautifully with small teams, and that Python’s ecosystem (Flask, pint, pendulum, etc.) handles everything from web APIs to advanced numerical modeling. It’s a fitting example of Python’s power to seamlessly connect hardware innovation, data science, and real-world product delivery.

Links from the show

Rod on Twitter: @rodsenra
GX Sweat Patch: gatorade.com

Work & Co.: work.co
Pint package: pint.readthedocs.io
unyt package: pypi.org/project/unyt
Pendulum: pendulum.eustace.io
MongoDB: mongodb.com
python-constraint package: github.com/python-constraint
PSF Developer Survey 2020: jetbrains.com
Rich: github.com
Textual: github.com

YouTube Live Stream: youtube.com
Episode transcripts: talkpython.fm

--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy

Talk Python's Mastodon Michael Kennedy's Mastodon