The Energy Data Scientist

The Energy Data Scientist

How to use **kwargs in Python. Energy Applications.

Understanding *args in Python

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

The more flexible our code is, the better its maintenance becomes. We want, as much as possible, to avoid modifying function signatures, updating every function call across our codebase etc. It’s very tiring and also very risky to errors.

» Join the community!
Visit skool.com, search for “Energy Data Scientist” «

The Problem with Fixed Parameters

Traditional Python functions use fixed parameters:

def register_generator(name, capacity, fuel_type):
    # function body

This works great much of the time but the problem is what happens when we need to make changes in this signature.

For example, this function is about registering a power generator and includes its name, installed capacity and fuel type. However, at some point it may be necessary that we also want to register its Ramp rate limits, Emissions factors, Minimum stable generation, Start-up costs, Geographic coordinates etc.

And the same can apply to every function call in our codebase.

**kwargs: The Flexible Solution

**kwargs (keyword arguments) lets you accept any number of named parameters without specifying them upfront. It means that you can pass as many keyword arguments as you want into a function. This makes your code more flexible.

Here are scenarios where **kwargs finds application in power systems:

1. Market Bid Submissions Different markets have different requirements. EPEX SPOT UK wants certain fields, PJM wants others, CAISO has its own format. With **kwargs, one function handles them all.

2. Generator Registration Systems Wind farms need wind speed data. Solar needs irradiance. Hydro needs water levels. Nuclear needs regulatory compliance fields. One flexible function accepts all types.

3. Energy Trading Notifications Some traders want email alerts. Others want SMS. Some want Slack. Some want all three plus a phone call. **kwargs makes this trivial.

4. Settlement Calculations Base energy charges, capacity payments, ancillary services, transmission fees, congestion charges, losses—the list varies by region and grows over time.

5. Contract Management Power Purchase Agreements (PPAs), Contracts for Difference (CfDs), hedging instruments—each has unique terms that **kwargs can accommodate without function rewrites.

6. Asset Monitoring Different assets report different telemetry. Turbines report vibration, transformers report oil temperature, inverters report DC voltage. One monitoring function handles all.

Why This Matters for Energy

The energy sector is evolving faster than ever. For example, in the power sector:

  • New renewable technologies

  • Changing market rules

  • Grid modernization

  • Decentralization

  • Battery storage integration

  • Electric vehicle charging

  • Hydrogen systems

Our code needs to be as flexible as the industry. **kwargs gives us that flexibility without having to constantly refactor our code.

Code Implementation

Below is a function for submitting renewable energy bids.

» Subscribe for complete Energy Data Science tutorials! «

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