Skip to content

Commit

Permalink
Merge pull request #131 from axiomhq/arne/v2-user
Browse files Browse the repository at this point in the history
Upgrade users.current to v2
  • Loading branch information
bahlo authored Sep 12, 2024
2 parents fb1e962 + 35e4f20 commit 8ceaece
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ Alternatively, if you have the [`pip`](https://pip.pypa.io/) package installed,
pip3 install axiom-py
```

Create an API token with the permissions you need in the
[Axiom settings](https://cloud.axiom.co/profile) and export it as
`AXIOM_TOKEN`.
If you use the [Axiom CLI](https://github.com/axiomhq/cli), run `eval $(axiom config export -f)` to configure your environment variables.

Otherwise create a personal token in [the Axiom settings](https://cloud.axiom.co/profile) and export it as `AXIOM_TOKEN`. Set `AXIOM_ORG_ID` to the organization ID from the settings page of the organization you want to access.

You can also configure the client using options passed to the client constructor:

```py
import axiom_py

client = axiom_py.Client("<api token>")
client = axiom_py.Client("<api token>", "<org id>")
```

Create and use a client like this:
Expand Down
3 changes: 3 additions & 0 deletions examples/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ def main():
client = Client()
dataset_name = "my-dataset"

# Get current user
print(client.users.current())

# List datasets
res = client.datasets.get_list()
for dataset in res:
Expand Down
12 changes: 9 additions & 3 deletions src/axiom_py/users.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
from typing import List
from .util import Util
from dataclasses import dataclass
from requests import Session


@dataclass
class Role:
id: str
name: str


@dataclass
class User:
"""An authenticated axiom user."""

id: str
name: str
emails: List[str]
email: str
role: Role


class UsersClient:
Expand All @@ -25,6 +31,6 @@ def current(self) -> User:
See https://axiom.co/docs/restapi/endpoints/getCurrentUser
"""
res = self.session.get("/v1/user")
res = self.session.get("/v2/user")
user = Util.from_dict(User, res.json())
return user

0 comments on commit 8ceaece

Please sign in to comment.