Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Expose legacy properties (#90)
Browse files Browse the repository at this point in the history
* expose legacy properties

* typo

* improve README
  • Loading branch information
malmans2 authored Sep 27, 2024
1 parent 8383d88 commit c263e15
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

CADS API Python client

Documentation: https://ecmwf-projects.github.io/cads-api-client/

The `ApiClient` requires the `url` to the API root and a valid API `key`. You can also set the `CADS_API_URL` and `CADS_API_KEY` environment variables, or use a configuration file. The configuration file must be located at `~/.cads-api-client.json`, or at the path specified by the `CADS_API_RC` environment variable.

```
$ cat $HOME/.cads-api-client.json
{"url": "https://cds.climate.copernicus.eu/api", "key": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}
```

It is possible (though not recommended) to use the API key of one of the test users, `00112233-4455-6677-c899-aabbccddeeff`. This key is used for anonymous tests and is designed to be the least performant option for accessing the system.

Draft Python API:
Expand Down
2 changes: 1 addition & 1 deletion cads_api_client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def get_accepted_licences(
self,
scope: Literal[None, "all", "dataset", "portal"] = None,
) -> list[dict[str, Any]]:
"""Retrieve acccepted licences.
"""Retrieve accepted licences.
Parameters
----------
Expand Down
19 changes: 18 additions & 1 deletion cads_api_client/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,18 +648,35 @@ def download(
self._check_size(target)
return target

# cdsapi backward compatibility methods
@property
def location(self) -> str:
"""File location.
Returns
-------
str
"""
result_href = self.asset["href"]
return urllib.parse.urljoin(self.response.url, result_href)

@property
def content_length(self) -> int:
"""File size in Bytes.
Returns
-------
int
"""
return int(self.asset["file:size"])

@property
def content_type(self) -> str:
"""File MIME type.
Returns
-------
int
"""
return str(self.asset["type"])


Expand Down

0 comments on commit c263e15

Please sign in to comment.