ee-client 0.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Daniel Guerrero
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.1
2
+ Name: ee-client
3
+ Version: 0.0.0
4
+ Summary: extends the capabilities of the earthengine-api by providing custom session management and client interactions
5
+ Author-email: Daniel Guerrero <dfgm2006@gmail.com>
6
+ Project-URL: Homepage, https://github.com/dfguerrerom/ee-client
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Topic :: Software Development :: Build Tools
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/x-rst
16
+ License-File: LICENSE
17
+ Requires-Dist: earthengine-api
18
+ Requires-Dist: httpx
19
+
20
+ Earth Engine Session Client
21
+ ===========================
22
+
23
+ ee-client extends the capabilities of the earthengine-api by providing custom session management and client interactions
24
+
25
+
26
+ ee-client is a Python package designed to extend the capabilities of the Google Earth Engine (GEE) API by providing custom session management and client interactions. This package allows users to make authenticated requests to the Earth Engine REST API using their own credentials, facilitating seamless integration and customization of GEE functionalities.
27
+
28
+ Key Features
29
+ ------------
30
+
31
+ - Custom Authentication:
32
+ - Session Management: Handle sessions efficiently with reusable session objects that store credentials and project information.
33
+ - Enhanced API Calls: Replace and extend existing GEE API calls with custom methods to suit specific project requirements.
34
+ - Integration with Existing GEE Objects: Seamlessly integrate custom methods into existing Earth Engine objects, allowing for intuitive and familiar usage.
35
+
36
+
37
+ Installation
38
+ ------------
39
+
40
+ To install the package, simply use pip:
41
+
42
+ .. code-block:: bash
43
+
44
+ pip install ee-client # Not yet developed
45
+
46
+ Usage
47
+ -----
48
+
49
+ Here are a few examples of how to use ee-client in your projects:
50
+
51
+ Initialization and Authentication
52
+ +++++++++++++++++++++++++++++++++
53
+
54
+ .. code-block:: python
55
+
56
+ from eeclient import Session, get_info, get_asset
57
+
58
+ # Define your credentials and project ID
59
+ credentials = {
60
+ "client_id": "your_client_id",
61
+ "client_secret": "your_client_secret",
62
+ "refresh_token": "your_refresh_token",
63
+ }
64
+ project = "your_project"
65
+
66
+ # Create a session object
67
+ session = Session(credentials, project)
68
+
69
+
70
+ Making API Calls
71
+ ++++++++++++++++
72
+
73
+ .. code-block:: python
74
+
75
+ import ee
76
+
77
+ # Initialize the Earth Engine library and authenticate
78
+ ee.Initialize()
79
+
80
+ # Example: Get information about an Earth Engine object
81
+ result = get_info(session, ee.Number(5))
82
+ print(result)
83
+
84
+ # Example: Get asset information
85
+ asset_info = get_asset(session, "users/your_username/your_asset")
86
+ print(asset_info)
87
+
88
+ Fetching Map Tiles:
89
+ +++++++++++++++++++
90
+
91
+ .. code-block:: python
92
+
93
+ from eeclient import get_map_id, get_map_tile
94
+
95
+ # Example: Get map ID for an Earth Engine image
96
+ image = ee.Image('COPERNICUS/S2/20190726T104031_20190726T104035_T31TGL')
97
+ map_id = get_map_id(session, image)
98
+
99
+ # Example: Get map tile layer
100
+ tile_layer = get_map_tile(map_id)
101
+ print(tile_layer)
102
+
103
+ Integration with Existing GEE Objects
104
+ +++++++++++++++++++++++++++++++++++++
105
+
106
+ WIP
107
+
108
+ .. code-block:: python
109
+
110
+ import ee
111
+ import eeclient
112
+
113
+ # Custom method to get information about an Earth Engine Number object
114
+ def custom_get_info(self, session):
115
+ return get_info(session, self)
116
+
117
+ # Extend the Earth Engine Number class with the custom method
118
+ ee.Number.custom_get_info = custom_get_info
119
+
120
+ # Usage
121
+ number = ee.Number(5)
122
+ result = number.eeclient.get_info(session)
123
+ print(result)
124
+
125
+
126
+ Contributing
127
+ ------------
128
+
129
+ We welcome contributions from the community. Please feel free to submit issues and pull requests to help improve this package.
130
+
131
+ Fork the repository
132
+ +++++++++++++++++++
133
+
134
+ Create a new branch (git checkout -b feature-branch).
135
+ Commit your changes (git commit -am 'Add new feature').
136
+ Push to the branch (git push origin feature-branch).
137
+ Create a new Pull Request.
138
+
139
+ License
140
+ -------
141
+ This project is licensed under the MIT License - see the LICENSE file for details.
142
+
@@ -0,0 +1,123 @@
1
+ Earth Engine Session Client
2
+ ===========================
3
+
4
+ ee-client extends the capabilities of the earthengine-api by providing custom session management and client interactions
5
+
6
+
7
+ ee-client is a Python package designed to extend the capabilities of the Google Earth Engine (GEE) API by providing custom session management and client interactions. This package allows users to make authenticated requests to the Earth Engine REST API using their own credentials, facilitating seamless integration and customization of GEE functionalities.
8
+
9
+ Key Features
10
+ ------------
11
+
12
+ - Custom Authentication:
13
+ - Session Management: Handle sessions efficiently with reusable session objects that store credentials and project information.
14
+ - Enhanced API Calls: Replace and extend existing GEE API calls with custom methods to suit specific project requirements.
15
+ - Integration with Existing GEE Objects: Seamlessly integrate custom methods into existing Earth Engine objects, allowing for intuitive and familiar usage.
16
+
17
+
18
+ Installation
19
+ ------------
20
+
21
+ To install the package, simply use pip:
22
+
23
+ .. code-block:: bash
24
+
25
+ pip install ee-client # Not yet developed
26
+
27
+ Usage
28
+ -----
29
+
30
+ Here are a few examples of how to use ee-client in your projects:
31
+
32
+ Initialization and Authentication
33
+ +++++++++++++++++++++++++++++++++
34
+
35
+ .. code-block:: python
36
+
37
+ from eeclient import Session, get_info, get_asset
38
+
39
+ # Define your credentials and project ID
40
+ credentials = {
41
+ "client_id": "your_client_id",
42
+ "client_secret": "your_client_secret",
43
+ "refresh_token": "your_refresh_token",
44
+ }
45
+ project = "your_project"
46
+
47
+ # Create a session object
48
+ session = Session(credentials, project)
49
+
50
+
51
+ Making API Calls
52
+ ++++++++++++++++
53
+
54
+ .. code-block:: python
55
+
56
+ import ee
57
+
58
+ # Initialize the Earth Engine library and authenticate
59
+ ee.Initialize()
60
+
61
+ # Example: Get information about an Earth Engine object
62
+ result = get_info(session, ee.Number(5))
63
+ print(result)
64
+
65
+ # Example: Get asset information
66
+ asset_info = get_asset(session, "users/your_username/your_asset")
67
+ print(asset_info)
68
+
69
+ Fetching Map Tiles:
70
+ +++++++++++++++++++
71
+
72
+ .. code-block:: python
73
+
74
+ from eeclient import get_map_id, get_map_tile
75
+
76
+ # Example: Get map ID for an Earth Engine image
77
+ image = ee.Image('COPERNICUS/S2/20190726T104031_20190726T104035_T31TGL')
78
+ map_id = get_map_id(session, image)
79
+
80
+ # Example: Get map tile layer
81
+ tile_layer = get_map_tile(map_id)
82
+ print(tile_layer)
83
+
84
+ Integration with Existing GEE Objects
85
+ +++++++++++++++++++++++++++++++++++++
86
+
87
+ WIP
88
+
89
+ .. code-block:: python
90
+
91
+ import ee
92
+ import eeclient
93
+
94
+ # Custom method to get information about an Earth Engine Number object
95
+ def custom_get_info(self, session):
96
+ return get_info(session, self)
97
+
98
+ # Extend the Earth Engine Number class with the custom method
99
+ ee.Number.custom_get_info = custom_get_info
100
+
101
+ # Usage
102
+ number = ee.Number(5)
103
+ result = number.eeclient.get_info(session)
104
+ print(result)
105
+
106
+
107
+ Contributing
108
+ ------------
109
+
110
+ We welcome contributions from the community. Please feel free to submit issues and pull requests to help improve this package.
111
+
112
+ Fork the repository
113
+ +++++++++++++++++++
114
+
115
+ Create a new branch (git checkout -b feature-branch).
116
+ Commit your changes (git commit -am 'Add new feature').
117
+ Push to the branch (git push origin feature-branch).
118
+ Create a new Pull Request.
119
+
120
+ License
121
+ -------
122
+ This project is licensed under the MIT License - see the LICENSE file for details.
123
+
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.1
2
+ Name: ee-client
3
+ Version: 0.0.0
4
+ Summary: extends the capabilities of the earthengine-api by providing custom session management and client interactions
5
+ Author-email: Daniel Guerrero <dfgm2006@gmail.com>
6
+ Project-URL: Homepage, https://github.com/dfguerrerom/ee-client
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Topic :: Software Development :: Build Tools
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/x-rst
16
+ License-File: LICENSE
17
+ Requires-Dist: earthengine-api
18
+ Requires-Dist: httpx
19
+
20
+ Earth Engine Session Client
21
+ ===========================
22
+
23
+ ee-client extends the capabilities of the earthengine-api by providing custom session management and client interactions
24
+
25
+
26
+ ee-client is a Python package designed to extend the capabilities of the Google Earth Engine (GEE) API by providing custom session management and client interactions. This package allows users to make authenticated requests to the Earth Engine REST API using their own credentials, facilitating seamless integration and customization of GEE functionalities.
27
+
28
+ Key Features
29
+ ------------
30
+
31
+ - Custom Authentication:
32
+ - Session Management: Handle sessions efficiently with reusable session objects that store credentials and project information.
33
+ - Enhanced API Calls: Replace and extend existing GEE API calls with custom methods to suit specific project requirements.
34
+ - Integration with Existing GEE Objects: Seamlessly integrate custom methods into existing Earth Engine objects, allowing for intuitive and familiar usage.
35
+
36
+
37
+ Installation
38
+ ------------
39
+
40
+ To install the package, simply use pip:
41
+
42
+ .. code-block:: bash
43
+
44
+ pip install ee-client # Not yet developed
45
+
46
+ Usage
47
+ -----
48
+
49
+ Here are a few examples of how to use ee-client in your projects:
50
+
51
+ Initialization and Authentication
52
+ +++++++++++++++++++++++++++++++++
53
+
54
+ .. code-block:: python
55
+
56
+ from eeclient import Session, get_info, get_asset
57
+
58
+ # Define your credentials and project ID
59
+ credentials = {
60
+ "client_id": "your_client_id",
61
+ "client_secret": "your_client_secret",
62
+ "refresh_token": "your_refresh_token",
63
+ }
64
+ project = "your_project"
65
+
66
+ # Create a session object
67
+ session = Session(credentials, project)
68
+
69
+
70
+ Making API Calls
71
+ ++++++++++++++++
72
+
73
+ .. code-block:: python
74
+
75
+ import ee
76
+
77
+ # Initialize the Earth Engine library and authenticate
78
+ ee.Initialize()
79
+
80
+ # Example: Get information about an Earth Engine object
81
+ result = get_info(session, ee.Number(5))
82
+ print(result)
83
+
84
+ # Example: Get asset information
85
+ asset_info = get_asset(session, "users/your_username/your_asset")
86
+ print(asset_info)
87
+
88
+ Fetching Map Tiles:
89
+ +++++++++++++++++++
90
+
91
+ .. code-block:: python
92
+
93
+ from eeclient import get_map_id, get_map_tile
94
+
95
+ # Example: Get map ID for an Earth Engine image
96
+ image = ee.Image('COPERNICUS/S2/20190726T104031_20190726T104035_T31TGL')
97
+ map_id = get_map_id(session, image)
98
+
99
+ # Example: Get map tile layer
100
+ tile_layer = get_map_tile(map_id)
101
+ print(tile_layer)
102
+
103
+ Integration with Existing GEE Objects
104
+ +++++++++++++++++++++++++++++++++++++
105
+
106
+ WIP
107
+
108
+ .. code-block:: python
109
+
110
+ import ee
111
+ import eeclient
112
+
113
+ # Custom method to get information about an Earth Engine Number object
114
+ def custom_get_info(self, session):
115
+ return get_info(session, self)
116
+
117
+ # Extend the Earth Engine Number class with the custom method
118
+ ee.Number.custom_get_info = custom_get_info
119
+
120
+ # Usage
121
+ number = ee.Number(5)
122
+ result = number.eeclient.get_info(session)
123
+ print(result)
124
+
125
+
126
+ Contributing
127
+ ------------
128
+
129
+ We welcome contributions from the community. Please feel free to submit issues and pull requests to help improve this package.
130
+
131
+ Fork the repository
132
+ +++++++++++++++++++
133
+
134
+ Create a new branch (git checkout -b feature-branch).
135
+ Commit your changes (git commit -am 'Add new feature').
136
+ Push to the branch (git push origin feature-branch).
137
+ Create a new Pull Request.
138
+
139
+ License
140
+ -------
141
+ This project is licensed under the MIT License - see the LICENSE file for details.
142
+
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.rst
3
+ pyproject.toml
4
+ ee_client.egg-info/PKG-INFO
5
+ ee_client.egg-info/SOURCES.txt
6
+ ee_client.egg-info/dependency_links.txt
7
+ ee_client.egg-info/requires.txt
8
+ ee_client.egg-info/top_level.txt
9
+ eeclient/__init__.py
10
+ eeclient/client.py
11
+ eeclient/data.py
12
+ eeclient/exceptions.py
@@ -0,0 +1,2 @@
1
+ earthengine-api
2
+ httpx
@@ -0,0 +1 @@
1
+ eeclient
@@ -0,0 +1,8 @@
1
+ __title__ = "eeclient"
2
+ __summary__ = "A client for Google Earth Engine"
3
+ __version__ = "0.0.0"
4
+
5
+ __author__ = "Daniel Guerrero"
6
+ __email__ = "dfgm2006@gmail.com"
7
+
8
+ __license__ = "MIT"
@@ -0,0 +1,67 @@
1
+ from typing import Literal
2
+ import httpx
3
+ from eeclient.exceptions import EERestException
4
+
5
+
6
+ class Session:
7
+ def __init__(self, credentials, ee_project):
8
+
9
+ self.credentials = credentials
10
+ self.project = ee_project
11
+
12
+ self.headers = {
13
+ "x-goog-user-project": ee_project,
14
+ "Authorization": f"Bearer {self._get_access_token()}",
15
+ }
16
+
17
+ self.client = httpx.Client(headers=self.headers)
18
+
19
+ def _set_url_project(self, url):
20
+ """Set the project in the url"""
21
+
22
+ return url.format(project=self.project)
23
+
24
+ def rest_call(
25
+ self,
26
+ method: Literal["GET", "POST"],
27
+ url: str,
28
+ data: dict = None,
29
+ ):
30
+ """Make a call to the Earth Engine REST API"""
31
+
32
+ url = self._set_url_project(url)
33
+
34
+ with httpx.Client(headers=self.headers) as client:
35
+
36
+ response = (
37
+ client.post(url, data=data) if method == "POST" else client.get(url)
38
+ )
39
+
40
+ if response.status_code >= 400:
41
+ if "application/json" in response.headers.get("Content-Type", ""):
42
+ raise EERestException(response.json().get("error", {}))
43
+ else:
44
+ raise EERestException(
45
+ {"code": response.status_code, "message": response.reason}
46
+ )
47
+
48
+ return response.json()
49
+
50
+ def _get_access_token(self):
51
+ """Get the access token from the refresh token"""
52
+
53
+ url = "https://oauth2.googleapis.com/token"
54
+
55
+ with httpx.Client() as client:
56
+
57
+ response = client.post(
58
+ url,
59
+ data={
60
+ "client_id": self.credentials["client_id"],
61
+ "client_secret": self.credentials["client_secret"],
62
+ "refresh_token": self.credentials["refresh_token"],
63
+ "grant_type": "refresh_token",
64
+ },
65
+ )
66
+
67
+ return response.json().get("access_token")
@@ -0,0 +1,92 @@
1
+ from ee.ee_exception import EEException
2
+
3
+ import json
4
+ import ee
5
+ from ee import serializer
6
+ from ee import _cloud_api_utils
7
+
8
+ from ee.data import TileFetcher
9
+ from ipyleaflet import TileLayer
10
+
11
+ from eeclient.client import Session
12
+
13
+
14
+ def get_map_id(session: Session, ee_image: ee.Image):
15
+
16
+ url = "https://earthengine.googleapis.com/v1alpha/projects/{project}/maps"
17
+
18
+ request_body = {
19
+ "expression": serializer.encode(ee_image, for_cloud_api=True),
20
+ "fileFormat": _cloud_api_utils.convert_to_image_file_format(None),
21
+ "bandIds": _cloud_api_utils.convert_to_band_list(None),
22
+ }
23
+
24
+ request_body = json.dumps(request_body)
25
+
26
+ response = session.rest_call("POST", url, data=request_body)
27
+ map_name = response["name"]
28
+
29
+ return map_name
30
+
31
+
32
+ def get_map_tile(map_name: str):
33
+
34
+ _tile_base_url = "https://earthengine.googleapis.com"
35
+ version = "v1"
36
+
37
+ url_format = "%s/%s/%s/tiles/{z}/{x}/{y}" % (
38
+ _tile_base_url,
39
+ version,
40
+ map_name,
41
+ )
42
+
43
+ map_id = {
44
+ "mapid": map_name,
45
+ "token": "",
46
+ "tile_fetcher": TileFetcher(url_format, map_name=map_name),
47
+ }
48
+
49
+ return TileLayer(
50
+ url=map_id["tile_fetcher"].url_format,
51
+ attribution="Google Earth Engine",
52
+ name="name",
53
+ max_zoom=24,
54
+ )
55
+
56
+
57
+ def get_info(session: Session, ee_object, workloadTag=None):
58
+ """Get the info of an Earth Engine object"""
59
+
60
+ data = {
61
+ "expression": serializer.encode(ee_object),
62
+ "workloadTag": workloadTag,
63
+ }
64
+
65
+ url = "https://earthengine.googleapis.com/v1/projects/{project}/value:compute"
66
+
67
+ return session.rest_call("POST", url, data=data)
68
+
69
+
70
+ def get_asset(session: Session, ee_asset_id: str):
71
+ """Get the asset info from the asset id"""
72
+
73
+ url = (
74
+ "https://earthengine.googleapis.com/v1alpha/projects/{project}/assets/"
75
+ + ee_asset_id
76
+ )
77
+
78
+ return session.rest_call("GET", url)
79
+
80
+
81
+ class EERestException(EEException):
82
+ def __init__(self, error):
83
+ self.message = error.get("message", "EE responded with an error")
84
+ super().__init__(self.message)
85
+ self.code = error.get("code", -1)
86
+ self.status = error.get("status", "UNDEFINED")
87
+ self.details = error.get("details")
88
+
89
+
90
+ getInfo = get_info
91
+ getAsset = get_asset
92
+ getMapTile = get_map_tile
@@ -0,0 +1,10 @@
1
+ from ee.ee_exception import EEException
2
+
3
+
4
+ class EERestException(EEException):
5
+ def __init__(self, error):
6
+ self.message = error.get("message", "EE responded with an error")
7
+ super().__init__(self.message)
8
+ self.code = error.get("code", -1)
9
+ self.status = error.get("status", "UNDEFINED")
10
+ self.details = error.get("details")
@@ -0,0 +1,49 @@
1
+ [project]
2
+ name = "ee-client"
3
+ version = "0.0.0"
4
+ description = "extends the capabilities of the earthengine-api by providing custom session management and client interactions"
5
+ readme = { file = "README.rst" , content-type = "text/x-rst" }
6
+ authors = [
7
+ { name = "Daniel Guerrero", email = "dfgm2006@gmail.com" }
8
+ ]
9
+ dependencies = [
10
+ "earthengine-api",
11
+ "httpx"
12
+ ]
13
+ classifiers = [
14
+ "Development Status :: 3 - Alpha",
15
+ "Intended Audience :: Developers",
16
+ "Topic :: Software Development :: Build Tools",
17
+ "License :: OSI Approved :: MIT License",
18
+ "Programming Language :: Python :: 3.9",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ ]
22
+ requires-python = ">=3.9"
23
+ urls = {Homepage = "https://github.com/dfguerrerom/ee-client"}
24
+
25
+ [tool.ruff]
26
+ ignore-init-module-imports = true
27
+ fix = true
28
+
29
+ [tool.ruff.flake8-quotes]
30
+ docstring-quotes = "double"
31
+
32
+ [tool.ruff.pydocstyle]
33
+ convention = "google"
34
+
35
+ [tool.pytest.ini_options]
36
+ testpaths = "tests"
37
+
38
+ [tool.coverage.run]
39
+ source = ["eeclient"]
40
+ branch = true
41
+
42
+ [tool.commitizen]
43
+ tag_format = "v$major.$minor.$patch$prerelease"
44
+ update_changelog_on_bump = false
45
+ version = "0.0.0"
46
+ version_files = [
47
+ "pyproject.toml:version",
48
+ "eeclient/__init__.py:__version__",
49
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+