landstac.auth

ERS authentication and session helpers.

Functions: - make_session: create a requests.Session with retries and headers - ers_login: log in to ERS (USGS) and return an authenticated session - ers_login_from_file: read credentials.json and log in - save_cookies_for_gdal: export session cookies to a Mozilla cookie file so

GDAL/rasterio can stream protected assets without downloading

Functions

ers_login(username, password[, token])

Log in to ERS and return an authenticated session.

ers_login_from_file([credentials_path])

Read credentials.json and perform ERS login.

make_session()

save_cookies_for_gdal(session[, cookiefile])

Save current session cookies into a Mozilla cookie file.

landstac.auth.ers_login(username, password, token=None)[source]

Log in to ERS and return an authenticated session.

Parameters:
  • username (str) – USGS ERS username.

  • password (str) – USGS ERS password.

  • token (str, optional) – Optional bearer token for authorization header.

Returns:

Authenticated session with ERS cookies.

Return type:

requests.Session

Note

If token is provided and accepted by the host, it is attached as Authorization header.

landstac.auth.ers_login_from_file(credentials_path='credentials.json')[source]

Read credentials.json and perform ERS login.

Parameters:

credentials_path (str) – Path to credentials JSON file.

Returns:

Authenticated session.

Return type:

requests.Session

Note

credentials.json schema:

{
  "username": "...",
  "password": "...",
  "token": null
}
landstac.auth.make_session()[source]
Return type:

Session

landstac.auth.save_cookies_for_gdal(session, cookiefile='usgs_cookies.txt')[source]

Save current session cookies into a Mozilla cookie file.

Parameters:
  • session (requests.Session) – Authenticated session.

  • cookiefile (str) – Path to save cookie file.

Returns:

Absolute path to saved cookie file.

Return type:

str

Note

Use with GDAL via environment variables:

CPL_CURL_COOKIEFILE=cookiefile
CPL_CURL_COOKIEJAR=cookiefile