The Energy Data Scientist

The Energy Data Scientist

How to use *args in Python. Application: Energy

Understanding *args in Python

Dr Spyros Giannelos's avatar
Dr Spyros Giannelos
Dec 16, 2025
∙ Paid

Join our community! Visit skool.com, search for “Energy Data Scientist”

When you’re developing code for electricity markets, you quickly encounter a fundamental challenge: the grid is never static.

On any given day, the wholesale electricity market processes bids from dozens of generators. Some days, fifty power stations are online. Other days, seventy. Wind farms enter and exit based on weather forecasts. Solar parks only bid during daylight hours.

This variability is a software design challenge.

Traditional function signatures lock you into fixed parameters. But in energy markets, you can’t predict how many generation sources will be active tomorrow, let alone next year as the grid evolves.

The Real-World Problem

Consider the UK’s day-ahead market process. On D-1 (the day before delivery), electricity grid operators need to register available capacity from every active generator. This isn’t a fixed list. It changes daily.

A function that registers generation capacity can’t have a predetermined number of parameters. You need a function that accepts whatever sources are available that day, whether it’s twenty sources or eighty.

This is very important. The European power market processes over €500 billion in annual trading volume. Market operators need software systems that are precise. A single miscalculation in capacity registration can cascade into imbalance charges worth millions of pounds.

Why This Matters for the Electricity Market

Electricity trading operates on tight deadlines. The EPEX SPOT UK is the company that operates the wholesale (specifically the day-ahead) electricity market in the United Kingdom (UK). It has a gate closure at 12:00 noon on the bidding day (i.e. day D-1). This means that on the bidding day, all participants must have submitted their bids by 12:00 noon.

Then, between 12:00 and 1pm an algorithm is run, known as ‘merit order’. So, this clearing algorithm has approximately one hour to process thousands of half-hourly bids, run merit order optimization, and publish results by 13:00. There’s no time for system administrators to manually configure function parameters in the code every morning. The software must dynamically handle whatever combination of generators is operational that day.

Understanding *args requires thinking differently about function design in Python. When you include this into your code, you’re telling Python “Accept whatever number of arguments we provide, and package them so I can iterate through them.”

When you write a function using *args, you’re building infrastructure that doesn’t need rewriting every day. Energy companies operate on thin margins. Software that requires constant modification creates operational risk.

Code Implementation: Variable Arguments in Action

Now let’s examine how *args works in practice for the electricity market.

Below we see the function register_available_capacity which takes the asterisk operator * . When used in a function definition, this operator collects any number of positional arguments into a tuple.

This function is run on the bidding day (D-1) before 12:00 noon , when all power stations and interconnectors register their available capacity for that day.

def register_available_capacity(*sources):

Join our community! Visit skool.com, search for “Energy Data Scientist”


User's avatar

Continue reading this post for free, courtesy of Dr Spyros Giannelos.

Or purchase a paid subscription.
© 2025 The Energy Data Scientist · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture