# Use the Python client

> Install the Budgets Python client, create it from an OpenStack SDK connection, and handle the errors it raises.

The `vexxhost-budgetclient` package is the Python client for Budgets. It signs in with the same session as the
OpenStack SDK, so it works with your existing `clouds.yaml`.

## Before you begin

Set up a `clouds.yaml` entry or an application credential. See
[Use OpenStack from Python](/developer/python).

## 1. Install the client

```sh
pip install vexxhost-budgetclient
```

## 2. Create the client

```python
import openstack
from budgetclient import Client

conn = openstack.connect(cloud="vexxhost")
budgets = Client("1", session=conn.session)
```

The client finds Budgets in the [service catalog](/identity/service-catalog).
The other Budgets guides call it `budgets`.

## 3. Make a call

Methods take and return dictionaries with the same fields as the API's JSON, so the
[API reference](/budgets/api) also describes each call. `budgets.budgets` manages budgets and `budgets.notification_channels` manages channels.

```python
for budget in budgets.budgets.list():
    print(budget["name"], budget["amount"], budget["currency"])
```

## 4. Handle errors

A failed request raises an exception from `budgetclient.exceptions`, such as `Conflict`,
`TooManyRequests` or `Unauthorized`. The exceptions are also `keystoneauth1.exceptions` HTTP errors.

| Attribute     | Contents                                                                 |
| ------------- | ------------------------------------------------------------------------ |
| `status_code` | The HTTP status.                                                         |
| `problem`     | The API's error document, with `title`, `detail` and any field `errors`. |
| `request_id`  | The `X-Request-ID` of the request, for support.                          |
| `retry_after` | Seconds to wait before retrying, on `429 Too Many Requests`.             |

```python
from budgetclient import exceptions

try:
    budgets.budgets.get("c7e1a5b3-9d2f-4e8c-a6b4-1f3d5e7c9a2b")
except exceptions.ClientException as error:
    print(error.status_code, error.request_id, error.problem["detail"])
    raise
```

## Next steps

* Use `budgets` in the Python examples of the other Budgets guides.
