Skip to main content

extends the capabilities of the earthengine-api by providing custom session management and client interactions

Project description

Tests PyPI version Python versions Conda-Forge version License

The Earth Engine Session Client is a Python package that extends the Google Earth Engine (GEE) API by introducing multi-user session management through custom authentication.

Why This Package?

While Google Earth Engine applications can be created using a global service account, this approach has significant limitations: users cannot access their private GEE assets without making them public. This package solves this problem by handling custom authentication, allowing each user to access their own private assets securely.

Unlike the standard GEE API—which relies on a global session object and does not support multi-user environments—this client ensures that each session is authenticated and managed independently with user-specific credentials.

Each session is instantiated via the EESession class, currently only accepts SEPAL headers as its only parameter. A valid ``sepal-session-id`` cookie must be present in these headers, as it is used to retrieve the corresponding GEE credentials. Once authenticated, the session exposes an operations property that provides easy access to key API methods.

Key Features

  • Custom User Authentication: Enable users to access their private GEE assets without requiring them to be public, solving the limitation of global service account approaches.

  • SEPAL-based Initialization: Create sessions using SEPAL headers. The required sepal-session-id cookie is automatically used to retrieve GEE credentials.

  • Multi-User Session Management: Encapsulate user-specific credentials and project data in independent EESession objects.

  • Enhanced API Operations: Access GEE functionalities via the operations property, which includes methods such as: - get_info: Retrieve detailed information about an Earth Engine object. - get_map_id: Generate a map ID for an Earth Engine image. - get_asset: Fetch information about a specific Earth Engine asset.

  • Seamless GEE Integration: Integrate custom methods into your existing Earth Engine workflow with minimal changes.

Installation

To install the package, simply use pip:

pip install ee-client

Usage

Initialization and Authentication

The Earth Engine Session Client must be initialized using SEPAL headers. Ensure that the headers include the ``sepal-session-id`` cookie, which is essential for retrieving the GEE credentials.

from eeclient import EESession

# Example SEPAL headers with the mandatory sepal-session-id cookie.
sepal_headers = {
    "cookie": [
        "sepal-session-id=your_session_id",
        "other_cookie=other_value"
    ],
    "sepal_user": [{
        "id": 123,
        "username": "your_username",
        "googleTokens": {
            "accessToken": "your_access_token",
            "refreshToken": "your_refresh_token",
            "accessTokenExpiryDate": 1234567890,
            "REFRESH_IF_EXPIRES_IN_MINUTES": 10,
            "projectId": "your_project_id",
            "legacyProject": "your_legacy_project"
        },
        "status": "active",
        "roles": ["role1", "role2"],
        "systemUser": False,
        "admin": False
    }]
}

# Create and validate the session with SEPAL headers
session = EESession(sepal_headers)

Making API Calls

After initializing the session, use the operations property to access the key GEE methods. For example, you can retrieve information about Earth Engine objects, generate map IDs, or fetch asset details:

import ee

# Initialize the Earth Engine library (this can use any authentication method/account)
# The purpose of this is to ensure the ee library is available for use
ee.Initialize()

# Use the operations available in the session
result_info = session.operations.get_info(ee.Number(5))
print(result_info) # the GEE server call is done using the custom EE client

# Example: Generate a map ID for an Earth Engine image
image = ee.Image('COPERNICUS/S2/20190726T104031_20190726T104035_T31TGL')
map_id = session.operations.get_map_id(image)
print(map_id)

# Example: Retrieve asset information
asset_info = session.operations.get_asset("users/your_username/your_asset")
print(asset_info)

Contributing

We welcome contributions from the community. If you wish to help improve this package, please submit issues or pull requests.

Forking and Branching

  1. Fork the repository.

  2. Create a new branch:

    git checkout -b feature-branch
  3. Commit your changes:

    git commit -am 'Add new feature'
  4. Push the branch:

    git push origin feature-branch
  5. Create a new Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

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

Source Distribution

ee_client-2.6.2.tar.gz (29.8 kB view details)

Uploaded Source

Built Distribution

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

ee_client-2.6.2-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file ee_client-2.6.2.tar.gz.

File metadata

  • Download URL: ee_client-2.6.2.tar.gz
  • Upload date:
  • Size: 29.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for ee_client-2.6.2.tar.gz
Algorithm Hash digest
SHA256 bf5c9783c40dfbd6e5ed01f375caa68478dea1284b8cfaaafc13e353b22d0ffa
MD5 2f96513a74a6aed6125befa061d597de
BLAKE2b-256 f3abbc53b6986510b31da52c2437559db527c5acf34d8d85aa08d9b53928308e

See more details on using hashes here.

File details

Details for the file ee_client-2.6.2-py3-none-any.whl.

File metadata

  • Download URL: ee_client-2.6.2-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for ee_client-2.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6e24b82a0beabfb813125add409f1e280a5f15785f80c62e741ad14ae5a00886
MD5 b3a6931d9b19bec91ae560d9b9d12f62
BLAKE2b-256 4f9182c309afbfac89ffcff29bb0ec40e1aa0496564ccf50a74531cc054467e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page