Get your API key from Settings – API key on the Energy Quantified web application.

There are two ways to provide your API key to the API client:

Provide API key in code

Import EnergyQuantified from the library, create a client and supply the API key. The actual API key is longer than the one provided in this example:

>>> from energyquantified import EnergyQuantified
>>> eq = EnergyQuantified(api_key='aaaa-bbbb-cccc-dddd')

(Optional) You may check whether or not the API key is valid like so:

>>> eq.is_api_key_valid()

Load API key from file

Create a new text file, let’s call it eq_api_key.txt in this example, and write the API key to it:


Then you can initialize the client like and provide the API key with a parameter called api_key_file. Make sure to provide the full path or the relative path to the directory where you run your program from:

>>> from energyquantified import EnergyQuantified
>>> eq = EnergyQuantified(api_key_file='eq_api_key.txt')

The last line above should fail with an error if it cannot find or read the file or if the file is empty.

Once you’ve authenticated, move on to the next step on how to discover data.

Authentication for Realto users

Those who subscribe to Energy Quantified’s API via the Realto marketplace must initialize the client using a RealtoConnection class. This class makes sure the requests are sent to Realto’s proxy servers and that the API key is provided in the HTTP header Realto requires you to use.

Import class RealtoConnection from the library, create a client and supply the details needed to connect to the Realto API. Notice that you must specify both an api_url and an api_key:

>>> from energyquantified import RealtoConnection
>>> eq = RealtoConnection(
>>>     api_url=RealtoConnection.API_URL_GERMANY,
>>>     api_key='abcdefghijklmnopqrstuvw'  # Supply your API key
>>> )

You can also store your API key in a file like you can with the default Energy Quantified client:

>>> from energyquantified import RealtoConnection
>>> eq = RealtoConnection(
>>>     api_url=RealtoConnection.API_URL_GERMANY,
>>>     api_key_file='realto_api_key.txt'  # A file with API key
>>> )

Each country is set up as a different API on Realto’s marketplace. As of this writing, the available products are:


These variables are nothing else than strings of the base URL for the specific API on Realto:

>>> RealtoConnection.API_URL_GERMANY

So if Energy Quantified adds more products to the Realto marketplace — but hasn’t updated the client yet — you can set the api_url parameter to the base URL of those API’s.


If you need to use a proxy, it can be configured for the entire session in both EnergyQuantified and RealtoConnection by providing the proxies parameter with a dictionary of proxies.

Example with EnergyQuantified:

>>> from energyquantified import EnergyQuantified
>>> proxies = {
>>>     'http': '',
>>>     'https': '',
>>> }
>>> eq = EnergyQuantified(
>>>     api_key='aaaa-bbbb-cccc-dddd',
>>>     proxies=proxies, # Supply proxies here
>>> )

Example with RealtoConnection:

>>> from energyquantified import RealtoConnection
>>> proxies = {
>>>     'http': '',
>>>     'https': '',
>>> }
>>> eq = RealtoConnection(
>>>     api_url=RealtoConnection.API_URL_GERMANY,
>>>     api_key='abcdefghijklmnopqrstuvw',
>>>     proxies=proxies,  # Supply proxies here
>>> )

Since the requests library is used internally in EnergyQuantified and RealtoConnection, refer to the proxies section in their documentation.

Get user details

If you want to get the details of the user associated with the API key, you can do so like this:

>>> eq.user.user()
     name="John Doe",
         name="ACME Inc.",
         account_manager=<AccountManager: name="Jane Doe", email="">
         <Subscription: "Power – Germany", access=PAYING, type=PACKAGE_AREA>,
         <Subscription: "Power – France", access=PAYING, type=PACKAGE_AREA>

Next step

See how to discover data.