BaseClient
geostudio.backends.base_client
BaseClient
BaseClient(
api_config: GeoFmSettings = None,
session: Session = None,
api_token: str = None,
api_key: str = None,
api_key_file: str = None,
geostudio_config_file: str = None,
*args,
**kwargs
)
This class provides methods for making HTTP requests to a Geospatial studio APIs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_config
|
GeoFmSettings
|
The configuration settings for the GeoFm API. Defaults to None. |
None
|
session
|
Session
|
A pre-configured requests session. Defaults to None. |
None
|
api_token
|
str
|
The API token for authentication. Defaults to None. |
None
|
api_key
|
str
|
The API key for authentication. Defaults to None. |
None
|
api_key_file
|
str
|
The path to the file containing the API key. Defaults to None. |
None
|
geostudio_config_file
|
str
|
The file path to the geostudio config path containing api_key + base_urls. |
None
|
*args
|
Variable length argument list. |
()
|
|
**kwargs
|
Arbitrary keyword arguments. |
{}
|
Raises:
| Type | Description |
|---|---|
GeoFMException
|
If no API token, API key, or API key file is provided. |
Attributes:
| Name | Type | Description |
|---|---|---|
api_config |
GeoFmSettings
|
The configuration settings for the GeoFm API. |
session |
Session
|
A pre-configured requests session. |
logger |
Logger
|
The logger instance for logging messages. |
Source code in geostudio/backends/base_client.py
api_url
property
Process both settings.BASE_GATEWAY_API_URL and settings.BASE_STUDIO_UI_URL 1. For both ensure they end with / 2. For settings.BASE_STUDIO_UI_URL it should only have one / and if there are others clip the rest of the url after the first / e.g. https//myui.com/ 3. For settings.BASE_GATEWAY_API_URL it should have only one / if it does not have 2 / enclosing poxy keyword. e.g. /proxy/ e.g. https//myapi.com/ or https//myapi.com/proxy/ otherwise clip the unwanted parts of the url 4. In the function if settings.BASE_STUDIO_UI_URL is present return the processed UI_URL from 2 above and only if settings.BASE_GATEWAY_API_URL is present return it after step 3
http_get
Sends an HTTP GET request to the specified endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The endpoint to send the GET request to. |
required |
params
|
dict
|
Query parameters to include in the GET request. |
None
|
output
|
str
|
The desired output format. |
None
|
data_field
|
str
|
The name of the data field to extract from the response. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
object |
The response data in the specified format. |
Source code in geostudio/backends/base_client.py
http_post
http_post(
endpoint,
data,
files: dict = None,
output=None,
data_field=None,
)
Sends an HTTP POST request to the specified endpoint with the given data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The API endpoint to send the POST request to. |
required |
data
|
dict
|
The data to be sent in the POST request body. |
required |
output
|
str
|
The desired output format. |
None
|
data_field
|
str
|
The key in the response JSON that contains the desired data. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
object |
The response data in the specified format. |
Source code in geostudio/backends/base_client.py
http_put_file
Uploads a file to a specified endpoint using a PUT request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The URL endpoint to send the PUT request to. |
required |
file_path
|
str
|
The path to the file to be uploaded. |
required |
output
|
str
|
The format of the response output. Default is None. |
None
|
data_field
|
str
|
The field in the response to extract. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
The response from the server in the specified output format. |
Source code in geostudio/backends/base_client.py
http_put
Sends an HTTP PUT request to the specified endpoint with the provided data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The URL endpoint to send the PUT request to. |
required |
data
|
dict or str
|
The data to be sent in the PUT request body. If a dictionary, it will be converted to JSON. |
required |
output
|
str
|
The desired output format. |
None
|
data_field
|
str
|
The field in the response to extract. |
None
|
file_path
|
str
|
If the data is a file path, the file will be read and sent as the request body. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
The formatted response data based on the provided output format. |
Source code in geostudio/backends/base_client.py
http_patch
Sends a PATCH request to the specified endpoint with the provided data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The URL endpoint to send the PATCH request to. |
required |
data
|
dict
|
The data to be sent in the body of the PATCH request. |
required |
output
|
str
|
The format of the response. |
None
|
data_field
|
str
|
The field in the response to extract. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
The formatted response data, or the raw response if no output format is specified. |
Source code in geostudio/backends/base_client.py
http_delete
Sends a DELETE request to the specified endpoint and returns the response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The URL endpoint to send the DELETE request to. |
required |
output
|
str
|
The format of the response. |
None
|
data_field
|
str
|
The field in the response to extract. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
object |
The response from the DELETE request, formatted according to the 'output' parameter. |
Source code in geostudio/backends/base_client.py
ResponseFormats
formated_output
formated_output(
response, output_fmt: str = JSON, data_field: str = None
) -> Union[DataFrame | Dict[str, Any | str]]
Formats the response data into the specified output format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
Response
|
The HTTP response object. |
required |
output_fmt
|
str
|
The desired output format. Defaults to ResponseFormats.JSON. |
JSON
|
data_field
|
str
|
The specific data field to extract from the response. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Union[DataFrame | Dict[str, Any | str]]
|
dict or pd.DataFrame: The formatted response data. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the specified output format is not supported. |
JSONDecodeError
|
If the response cannot be parsed as JSON. |