Skip to main content

EarthScope SDK

An SDK for interacting with EarthScope's APIs

Getting Started

Installation

Install from PyPI

pip install earthscope-sdk

Or with optional dependencies:

# efficient data access (Arrow)
pip install earthscope-sdk[arrow]

# dropoff category validators (per category, or all)
pip install earthscope-sdk[miniseed]
pip install earthscope-sdk[stationxml]
pip install earthscope-sdk[dropoff]

[!NOTE] Through 1.x, MiniSEED and StationXML validation libraries are also installed with the base package. Prefer the extras above when pinning dependencies; in 2.0 they will be required for those validators.

Usage

For detailed usage info and examples, visit our SDK docs.

# Import and create a client
from earthscope_sdk import EarthScopeClient

client = EarthScopeClient()

# Example client method usage; retrieve your user profile
profile = client.user.get_profile()
print(profile)

# Client cleanup
client.close()

Async Usage

There is also an async client available

import asyncio
from earthscope_sdk import AsyncEarthScopeClient

async def main():
    client = AsyncEarthScopeClient()

    profile = await client.user.get_profile()
    print(profile)

    await client.close()

asyncio.run(main())

Context Managers

Client classes can also be used as context managers to ensure resource cleanup occurs.

# sync
with EarthScopeClient() as client:
   client.user.get_profile()

# async
async with AsyncEarthScopeClient() as client:
   await client.user.get_profile()

Bootstrapping Authentication

There are a few methods of bootstrapping authentication for the SDK.

Once refreshable credentials are available to the SDK, it will transparently handle access token refresh on your behalf.

Same host

If you have the EarthScope CLI installed on the same host that is running your application which uses earthscope-sdk, you can simply log in using the CLI. The CLI shares credentials and configuration with this SDK (when running on the same host).

Running es login will open your browser and prompt you to log in to your EarthScope account.

$ es login
Attempting to automatically open the SSO authorization page in your default browser.
If the browser does not open or you wish to use a different device to authorize this request, open the following URL:

https://login.earthscope.org/activate?user_code=ABCD-EFGH

Successful login! Access token expires at 2024-12-27 18:50:37+00:00

Now when you run your application, earthscope-sdk will find your credentials.

Different hosts

Sometimes your workload runs on different hosts than your main workstation and you cannot feasibly "log in" on all of them. For example, maybe you're running many containers in your workload.

You can still use the EarthScope CLI to facilitate auth for applications on other machines.

  1. Use the CLI on your primary workstation as described above to log in.

  2. Use the CLI to retrieve your refresh token.

    $ es user get-refresh-token
    <your-refresh-token>
    

    Note: your refresh token should be treated as a secret credential. Anyone with a valid refresh token can use it to continually retrieve new access tokens on your behalf.

  3. Pass this refresh token to all the hosts needing auth for the earthscope-sdk. For example, inject the ES_OAUTH2__REFRESH_TOKEN environment variable on these hosts.

    export ES_OAUTH2__REFRESH_TOKEN="<your-refresh-token>"
    

SDK Settings

SDK Settings are provided via the following methods (in order of precedence):

  1. initialization arguments (e.g. via class constructors)
  2. environment variables
  3. dotenv file (.env) variables
  4. user's home directory settings files
    1. ~/.earthscope/config.toml (for configuration)
    2. ~/.earthscope/<profile-name>/tokens.json (for tokens)
  5. legacy EarthScope CLI v0 credentials
  6. default settings

SDK configuration is managed by the SdkSettings class, and calling the constructor performs this settings loading chain.

from earthscope_sdk.config.settings import SdkSettings

settings = SdkSettings()  # loads settings via loading chain

For more details on SDK configuration, including what options are available, see our settings docs.

Contributing

For details on contributing to the EarthScope SDK, please see:

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

earthscope_sdk-1.7.2.tar.gz (94.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

earthscope_sdk-1.7.2-py3-none-any.whl (98.7 kB view details)

Uploaded Python 3

File details

Details for the file earthscope_sdk-1.7.2.tar.gz.

File metadata

  • Download URL: earthscope_sdk-1.7.2.tar.gz
  • Upload date:
  • Size: 94.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for earthscope_sdk-1.7.2.tar.gz
Algorithm Hash digest
SHA256 d966dc75048e862a56c9e7c632f8549d2c4f6bd9bbf026f9d9d781128881f546
MD5 bec481e12aa55d2789292abd8811e11d
BLAKE2b-256 a530270c3229323211b58f22a1eb8473357a87689beff932afe3be382be3df13

See more details on using hashes here.

File details

Details for the file earthscope_sdk-1.7.2-py3-none-any.whl.

File metadata

  • Download URL: earthscope_sdk-1.7.2-py3-none-any.whl
  • Upload date:
  • Size: 98.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for earthscope_sdk-1.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 620ff82398cc4ac54f3a8639fbab9b17036531bd3df26ea6076fa421b233e382
MD5 5f94f5527c2d15a0bede53c3774e20fe
BLAKE2b-256 113693f22cea2fdfcb1778c3bb281a634d826ce797ad6b8c533628803858ba0f

See more details on using hashes here.

Release history Release notifications | RSS feed

1.8.0

2 files

This release

1.7.2 This release

2 files

1.7.1

2 files

1.7.0

2 files

1.6.1

2 files

1.6.0

2 files

1.5.0

2 files

1.4.1

2 files

1.4.0

2 files

1.3.1

2 files

1.3.0

2 files

1.2.0

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page