8000 Add the config token directly in the request instead of creating a config file · Issue #144 · ecmwf/cdsapi · GitHub
[go: up one dir, main page]

Skip to content

Add the config token directly in the request instead of creating a config file #144

Open

Description

@12rambau

Is your feature request related to a problem? Please describe.

I work in standalone data integration pipeline and it's tedious to write the config file from the environment variable values every time a new one is triggered. Would it be possible to add the API credentials directly in the request ?

import cdsapi

dataset = "reanalysis-era5-single-levels"
request = {
    "product_type": ["reanalysis"],
    "variable": ["2m_temperature"],
    "year": ["2025"],
    "month": ["05"],
    "day": ["08"],
    "time": ["07:00", "08:00", "09:00"],
    "data_format": "grib",
    "download_format": "unarchived",
    "api_key": tototututata

}

client = cdsapi.Client()
client.retrieve(dataset, request).download()

Organisation

Louis Dreyfus Company

Activity

  1. veenstrajelmer commented on May 15, 2025

    @veenstrajelmer

    @12rambau you can just use environment variables CDSAPI_URL and CDSAPI_KEY, so what you want is already possible and very simple to achieve. cdsapi will just take the values from the env vars and work as it always does. Could you check this and close the issue if it indeed works for you?

  2. 12rambau commented on May 15, 2025

    @12rambau
    Author

    oh thatt's absolutely perfect, can you point me to the documetnation that describes this behaviour ? I did't manage to find it and I would love to share it with my colleagues.

  3. veenstrajelmer commented on May 15, 2025

    @veenstrajelmer

    I am also just another user and I am not aware of any documentation of cdsapi to be honest, besides the examples on the cds website. But this is the code where the env vars are read:

    cdsapi/cdsapi/api.py

    Lines 48 to 52 in 72d7cec

    def get_url_key_verify(url, key, verify):
    if url is None:
    url = os.environ.get("CDSAPI_URL")
    if key is None:
    key = os.environ.get("CDSAPI_KEY")

    And cdsapi also uses env vars in their github testbank:

    CDSAPI_URL: https://cds.climate.copernicus.eu/api
    CDSAPI_KEY: ${{ secrets.CDSAPI_KEY_2024 }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0