pydo


Namepydo JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/digitalocean/pydo
SummaryThe official client for interacting with the DigitalOcean API
upload_time2023-11-29 17:42:46
maintainer
docs_urlNone
authorAPI Engineering
requires_python>=3.7.2,<4.0.0
licenseApache-2.0
keywords digitalocean api client
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # **PyDo**

`pydo` is the official Python client library that allows
Python developers to interact with and manage their DigitalOcean
resources through a Python abstraction layer on top of the raw
[DigitalOcean API HTTP Interface](https://developers.digitalocean.com/documentation/v2/).

A top priority of this project is to ensure the client abides by the API
contract. Therefore, the client itself wraps a generated client based
on the [DigitalOcean OpenAPI Specification](https://github.com/digitalocean/openapi) to support all of DigitalOcean's HTTP APIs.

# **Getting Started With the Client**

## Prerequisites

- Python version: >= 3.7.2

## Installation

To install from pip:

```shell
    pip install git+https://github.com/digitalocean/pydo.git
```

or, if repo is cloned locally:

```shell
    pip install /<PATH>/<TO>/pydo
```

To install from source:

```shell
make install
```

## **`pydo` Quickstart**

> A quick guide to getting started with the client.

`pydo` must be initialized with `pydo.Client()`. A DigitalOcean API Token is required. The token can be passed explicitly to `pydo.Client()`, as such:

```python
import os
from pydo import Client

client = Client(token=os.getenv("$DIGITALOCEAN_TOKEN"))
```

#### Example of Using `pydo` to Access DO Resources

Find below a working example for GETting a ssh_key ([per this http request](https://docs.digitalocean.com/reference/api/api-reference/#operation/sshKeys_list)) and printing the ID associated with the ssh key. If you'd like to try out this quick example, you can follow [these instructions](https://docs.digitalocean.com/products/droplets/how-to/add-ssh-keys/) to add ssh keys to your DO account.

```python
import os
from pydo import Client

client = Client(token=os.getenv("$DIGITALOCEAN_TOKEN"))

ssh_keys_resp = client.ssh_keys.list()
for k in ssh_keys_resp["ssh_keys"]:
    print(f"ID: {k['id']}, NAME: {k['name']}, FINGERPRINT: {k['fingerprint']}")
```

The above code snippet should output the following:

```shell
ID: 123456, NAME: my_test_ssh_key, FINGERPRINT: 5c:74:7e:60:28:69:34:ca:dd:74:67:c3:f3:00:7f:fe
ID: 123457, NAME: my_prod_ssh_key, FINGERPRINT: eb:76:c7:2a:d3:3e:80:5d:ef:2e:ca:86:d7:79:94:0d
```

**Consult the full list of supported DigitalOcean API endpoints in [PyDo's documentation](https://pydo.readthedocs.io/en/latest/).**

**Note**: More working examples can be found [here](https://github.com/digitalocean/pydo/tree/main/examples).

#### Pagination Example

Below is an example on handling pagination. One must parse the URL to find the
next page.

```python
resp = self.client.ssh_keys.list(per_page=50, page=page)
pages = resp.links.pages
if 'next' in pages.keys():
    parsed_url = urlparse(pages['next'])
    page = parse_qs(parsed_url.query)['page'][0]
else:
    paginated = False
```

#### Retries and Backoff

By default the client uses the same retry policy as the [Azure SDK for Python](https://learn.microsoft.com/en-us/python/api/azure-core/azure.core.pipeline.policies.retrypolicy?view=azure-python).
retry policy. If you'd like to modify any of these values, you can pass them as keywords to your client initialization:

```python
client = Client(token=os.getenv("$DIGITALOCEAN_TOKEN"), retry_total=3)
```

or

```python
client = Client(token=os.getenv("$DIGITALOCEAN_TOKEN"), retry_policy=MyRetryPolicy())
```

# **Contributing**

>Visit our [Contribuing Guide](CONTRIBUTING.md) for more information on getting
involved in developing this client.

# **Tests**

>The tests included in this repo are used to validate the generated client.
We use `pytest` to define and run the tests.

**_Requirements_**

- Python 3.7+
  - Can be installed using something like
    [pyenv](https://github.com/pyenv/pyenv)
    - used to manage different installed versions of python.
    - can also manage python virtual environments (with a plugin)
  - [Poetry](https://python-poetry.org/docs/#installation).
    - can also be configured to manage python virtual environments.

There are two types of test suites in the `tests/` directory.

#### Mocked Tests: `tests/mocked/`

Tests in the `mocked` directory include:

- tests that validate the generated client has all the expected classes and
  methods for the respective API resources and operations.
- tests that exercise individual operations against mocked responses.

These tests do not act against the real API so no real resources are created.

To run mocked tests, run:

```shell
make test-mocked
```

#### Integration Tests: `tests/integration/`

Tests in the `integration` directory include tests that simulate specific
scenarios a customer might use the client for to interact with the API.
**_IMPORTANT:_** these tests require a valid API token and **_DO_** create real
resources on the respective DigitalOcean account.

To run integration tests, run:

```shell
DIGITALOCEAN_TOKEN=... make test-integration
```

#### Test Customizations

Some test values can be customized so integration tests can exercise different
scenarios. For example, test use a default region to create resources. All the
default values are managed in the
[tests/integration/defaults.py](tests/integration/defaults.py) file. Any value
that has `environ.get()` can be overwritten by setting the respective environment
variable.

#### Tests with Docker

The included Dockerfile is a developler convenience to test the package in
isolation.

To use it, first build the image. Run:

```shell
docker build -t pydo:dev .
```

##### Use the interactive python shell

Open the python shell:

```shell
docker run -it --rm --name pydo pydo:dev python
```

The above will launch an interactive python shell and display the following:

```shell
Skipping virtualenv creation, as specified in config file.
Python 3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 07:06:46) [GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
```

From here you can use the client interactively:

```shell
>>> from pydo import Client
>>> c = Client($DIGITALOCEAN_TOKEN)
>>> c.droplets.get()
```

Alternatively, the tests can be run by attaching the tests as a volume and
running pytest directly.

Run:

```shell
docker run -it --rm --name pydo -v $PWD/tests:/tests pydo:dev pytest tests/mocked
```

# **Known Issues**

>This selection lists the known issues of the client generator.

#### `kubernetes.get_kubeconfig` Does not serialize response content

In the generated python client, when calling client.kubernetes.get_kubeconfig(clust_id), the deserialization logic raises an error when the response content-type is applicaiton/yaml. We need to determine if the spec/schema can be configured such that the generator results in functions that properly handle the content. We will likely need to report the issue upstream to request support for the content-type.

#### `invoices.get_pdf_by_uuid(invoice_uuid=invoice_uuid_param)` Does not return PDF

In the generated python client, when calling `invoices.get_pdf_by_uuid`, the response returns a Iterator[bytes] that does not format correctly into a PDF.

#### Getting documentation via cli "help(<client function>)"

Currently, calling the "help(<client function>)" includes the API documentation for the respective operation which is substantial and can be confusing in the context of this client.

# **Roadmap**

>This section lists short-term and long-term goals for the project.
**Note**: These are goals, not necessarily commitments. The sections are not intended to represent exclusive focus during these terms.

Short term:

> Usability, stability, and marketing.

Short term, we are focused on improving usability and user productivity (part of this is getting the word out).

- Documentation
  - Support an automated process for creating comprehensive documentation that explains working of codes
  - Support a clean cli `help(<client function>)` documentation solution
- Release stability
  - define release strategy
  - pip release

Long term:

> Model support, expand on supporting functions

- The client currently inputs and outputs JSON dictionaries. Adding models would unlock features such as typing and validation.
- Add supporting functions to elevate customer experience (i.e. adding a funtion that surfaces IP address for a Droplet)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/digitalocean/pydo",
    "name": "pydo",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7.2,<4.0.0",
    "maintainer_email": "",
    "keywords": "digitalocean,api,client",
    "author": "API Engineering",
    "author_email": "api-engineering@digitalocean.com",
    "download_url": "https://files.pythonhosted.org/packages/3b/77/ae8755f3783edb306721cfd5a2ef401bed7865f4100b27f5cf22e1d93c8b/pydo-0.2.0.tar.gz",
    "platform": null,
    "description": "# **PyDo**\n\n`pydo` is the official Python client library that allows\nPython developers to interact with and manage their DigitalOcean\nresources through a Python abstraction layer on top of the raw\n[DigitalOcean API HTTP Interface](https://developers.digitalocean.com/documentation/v2/).\n\nA top priority of this project is to ensure the client abides by the API\ncontract. Therefore, the client itself wraps a generated client based\non the [DigitalOcean OpenAPI Specification](https://github.com/digitalocean/openapi) to support all of DigitalOcean's HTTP APIs.\n\n# **Getting Started With the Client**\n\n## Prerequisites\n\n- Python version: >= 3.7.2\n\n## Installation\n\nTo install from pip:\n\n```shell\n    pip install git+https://github.com/digitalocean/pydo.git\n```\n\nor, if repo is cloned locally:\n\n```shell\n    pip install /<PATH>/<TO>/pydo\n```\n\nTo install from source:\n\n```shell\nmake install\n```\n\n## **`pydo` Quickstart**\n\n> A quick guide to getting started with the client.\n\n`pydo` must be initialized with `pydo.Client()`. A DigitalOcean API Token is required. The token can be passed explicitly to `pydo.Client()`, as such:\n\n```python\nimport os\nfrom pydo import Client\n\nclient = Client(token=os.getenv(\"$DIGITALOCEAN_TOKEN\"))\n```\n\n#### Example of Using `pydo` to Access DO Resources\n\nFind below a working example for GETting a ssh_key ([per this http request](https://docs.digitalocean.com/reference/api/api-reference/#operation/sshKeys_list)) and printing the ID associated with the ssh key. If you'd like to try out this quick example, you can follow [these instructions](https://docs.digitalocean.com/products/droplets/how-to/add-ssh-keys/) to add ssh keys to your DO account.\n\n```python\nimport os\nfrom pydo import Client\n\nclient = Client(token=os.getenv(\"$DIGITALOCEAN_TOKEN\"))\n\nssh_keys_resp = client.ssh_keys.list()\nfor k in ssh_keys_resp[\"ssh_keys\"]:\n    print(f\"ID: {k['id']}, NAME: {k['name']}, FINGERPRINT: {k['fingerprint']}\")\n```\n\nThe above code snippet should output the following:\n\n```shell\nID: 123456, NAME: my_test_ssh_key, FINGERPRINT: 5c:74:7e:60:28:69:34:ca:dd:74:67:c3:f3:00:7f:fe\nID: 123457, NAME: my_prod_ssh_key, FINGERPRINT: eb:76:c7:2a:d3:3e:80:5d:ef:2e:ca:86:d7:79:94:0d\n```\n\n**Consult the full list of supported DigitalOcean API endpoints in [PyDo's documentation](https://pydo.readthedocs.io/en/latest/).**\n\n**Note**: More working examples can be found [here](https://github.com/digitalocean/pydo/tree/main/examples).\n\n#### Pagination Example\n\nBelow is an example on handling pagination. One must parse the URL to find the\nnext page.\n\n```python\nresp = self.client.ssh_keys.list(per_page=50, page=page)\npages = resp.links.pages\nif 'next' in pages.keys():\n    parsed_url = urlparse(pages['next'])\n    page = parse_qs(parsed_url.query)['page'][0]\nelse:\n    paginated = False\n```\n\n#### Retries and Backoff\n\nBy default the client uses the same retry policy as the [Azure SDK for Python](https://learn.microsoft.com/en-us/python/api/azure-core/azure.core.pipeline.policies.retrypolicy?view=azure-python).\nretry policy. If you'd like to modify any of these values, you can pass them as keywords to your client initialization:\n\n```python\nclient = Client(token=os.getenv(\"$DIGITALOCEAN_TOKEN\"), retry_total=3)\n```\n\nor\n\n```python\nclient = Client(token=os.getenv(\"$DIGITALOCEAN_TOKEN\"), retry_policy=MyRetryPolicy())\n```\n\n# **Contributing**\n\n>Visit our [Contribuing Guide](CONTRIBUTING.md) for more information on getting\ninvolved in developing this client.\n\n# **Tests**\n\n>The tests included in this repo are used to validate the generated client.\nWe use `pytest` to define and run the tests.\n\n**_Requirements_**\n\n- Python 3.7+\n  - Can be installed using something like\n    [pyenv](https://github.com/pyenv/pyenv)\n    - used to manage different installed versions of python.\n    - can also manage python virtual environments (with a plugin)\n  - [Poetry](https://python-poetry.org/docs/#installation).\n    - can also be configured to manage python virtual environments.\n\nThere are two types of test suites in the `tests/` directory.\n\n#### Mocked Tests: `tests/mocked/`\n\nTests in the `mocked` directory include:\n\n- tests that validate the generated client has all the expected classes and\n  methods for the respective API resources and operations.\n- tests that exercise individual operations against mocked responses.\n\nThese tests do not act against the real API so no real resources are created.\n\nTo run mocked tests, run:\n\n```shell\nmake test-mocked\n```\n\n#### Integration Tests: `tests/integration/`\n\nTests in the `integration` directory include tests that simulate specific\nscenarios a customer might use the client for to interact with the API.\n**_IMPORTANT:_** these tests require a valid API token and **_DO_** create real\nresources on the respective DigitalOcean account.\n\nTo run integration tests, run:\n\n```shell\nDIGITALOCEAN_TOKEN=... make test-integration\n```\n\n#### Test Customizations\n\nSome test values can be customized so integration tests can exercise different\nscenarios. For example, test use a default region to create resources. All the\ndefault values are managed in the\n[tests/integration/defaults.py](tests/integration/defaults.py) file. Any value\nthat has `environ.get()` can be overwritten by setting the respective environment\nvariable.\n\n#### Tests with Docker\n\nThe included Dockerfile is a developler convenience to test the package in\nisolation.\n\nTo use it, first build the image. Run:\n\n```shell\ndocker build -t pydo:dev .\n```\n\n##### Use the interactive python shell\n\nOpen the python shell:\n\n```shell\ndocker run -it --rm --name pydo pydo:dev python\n```\n\nThe above will launch an interactive python shell and display the following:\n\n```shell\nSkipping virtualenv creation, as specified in config file.\nPython 3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 07:06:46) [GCC 10.3.0] on linux\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>>\n```\n\nFrom here you can use the client interactively:\n\n```shell\n>>> from pydo import Client\n>>> c = Client($DIGITALOCEAN_TOKEN)\n>>> c.droplets.get()\n```\n\nAlternatively, the tests can be run by attaching the tests as a volume and\nrunning pytest directly.\n\nRun:\n\n```shell\ndocker run -it --rm --name pydo -v $PWD/tests:/tests pydo:dev pytest tests/mocked\n```\n\n# **Known Issues**\n\n>This selection lists the known issues of the client generator.\n\n#### `kubernetes.get_kubeconfig` Does not serialize response content\n\nIn the generated python client, when calling client.kubernetes.get_kubeconfig(clust_id), the deserialization logic raises an error when the response content-type is applicaiton/yaml. We need to determine if the spec/schema can be configured such that the generator results in functions that properly handle the content. We will likely need to report the issue upstream to request support for the content-type.\n\n#### `invoices.get_pdf_by_uuid(invoice_uuid=invoice_uuid_param)` Does not return PDF\n\nIn the generated python client, when calling `invoices.get_pdf_by_uuid`, the response returns a Iterator[bytes] that does not format correctly into a PDF.\n\n#### Getting documentation via cli \"help(<client function>)\"\n\nCurrently, calling the \"help(<client function>)\" includes the API documentation for the respective operation which is substantial and can be confusing in the context of this client.\n\n# **Roadmap**\n\n>This section lists short-term and long-term goals for the project.\n**Note**: These are goals, not necessarily commitments. The sections are not intended to represent exclusive focus during these terms.\n\nShort term:\n\n> Usability, stability, and marketing.\n\nShort term, we are focused on improving usability and user productivity (part of this is getting the word out).\n\n- Documentation\n  - Support an automated process for creating comprehensive documentation that explains working of codes\n  - Support a clean cli `help(<client function>)` documentation solution\n- Release stability\n  - define release strategy\n  - pip release\n\nLong term:\n\n> Model support, expand on supporting functions\n\n- The client currently inputs and outputs JSON dictionaries. Adding models would unlock features such as typing and validation.\n- Add supporting functions to elevate customer experience (i.e. adding a funtion that surfaces IP address for a Droplet)\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "The official client for interacting with the DigitalOcean API",
    "version": "0.2.0",
    "project_urls": {
        "Documentation": "https://pydo.readthedocs.io/",
        "Homepage": "https://github.com/digitalocean/pydo",
        "Repository": "https://github.com/digitalocean/pydo"
    },
    "split_keywords": [
        "digitalocean",
        "api",
        "client"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "26169da2acd8e422b106ceb067de2999e4f8b6a741cbb8ad31fe473173299e37",
                "md5": "90ef9c6cd07ca33c99c609dc6e0e0f36",
                "sha256": "f1d42fa6778eb69325e74755c2d6c46983947be01a8c9dcac1f7552ef14a6823"
            },
            "downloads": -1,
            "filename": "pydo-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "90ef9c6cd07ca33c99c609dc6e0e0f36",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7.2,<4.0.0",
            "size": 1117693,
            "upload_time": "2023-11-29T17:42:44",
            "upload_time_iso_8601": "2023-11-29T17:42:44.794609Z",
            "url": "https://files.pythonhosted.org/packages/26/16/9da2acd8e422b106ceb067de2999e4f8b6a741cbb8ad31fe473173299e37/pydo-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3b77ae8755f3783edb306721cfd5a2ef401bed7865f4100b27f5cf22e1d93c8b",
                "md5": "0798420e09c8cee8badac7ab4135c1d3",
                "sha256": "8e53903169461956f52f73c5c10f5e926b1ec33de2277a938e6a047ff9281dc5"
            },
            "downloads": -1,
            "filename": "pydo-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0798420e09c8cee8badac7ab4135c1d3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7.2,<4.0.0",
            "size": 1097046,
            "upload_time": "2023-11-29T17:42:46",
            "upload_time_iso_8601": "2023-11-29T17:42:46.951028Z",
            "url": "https://files.pythonhosted.org/packages/3b/77/ae8755f3783edb306721cfd5a2ef401bed7865f4100b27f5cf22e1d93c8b/pydo-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-29 17:42:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "digitalocean",
    "github_project": "pydo",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "pydo"
}
        
Elapsed time: 0.14736s