evrim


Nameevrim JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummarySimple client for Evrim
upload_time2024-09-15 18:08:56
maintainerNone
docs_urlNone
authorChris
requires_python<4.0,>=3.12
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![codecov](https://codecov.io/gh/csmizzle/evrim-client/graph/badge.svg?token=E2V35OBJCA)](https://codecov.io/gh/csmizzle/evrim-client)

# Evrim Client
A simple Python client to interact with Evrim's REST API.

## Authentication
Evrim's REST API uses [JSON Web Tokens](https://jwt.io/introduction) (JWT) for authentication. Users can either obtain one using their username and password or use an existing **valid** JWT.

### Username/Password Authentication
Let's start by obtaining a JWT using our username and password. When initializing `Evrim`, the client will authenticate using the provided url, username, and password and obtain a valid JWT.

```python
from evrim import Evrim
import os

# access env variables
url = os.getenv("EVRIM_URL")
username = os.getenv("EVRIM_USERNAME")
password = os.getenv("EVRIM_PASSWORD")

# authenticate using url, username, and password
client = Evrim(
    url=url
    username=username,
    password=password
)
```

If this authentication is successful, two tokens are then issued to the user:
- `access`: Bearer token used in all subsequent requests in the `Authorization` header
- `refresh`: Token used to obtain a new `access` token once it expires

### Token Validation
JWTs expire after a certain amount of time. To check if your token is still valid, `Evrim` provides the `validate_token` function.

```python
from evrim import Evrim
from time import sleep
import os

# access env variables
url = os.getenv("EVRIM_URL")
username = os.getenv("EVRIM_USERNAME")
password = os.getenv("EVRIM_PASSWORD")

# authenticate using url, username, and password
client = Evrim(
    url=url
    username=username,
    password=password
)

# let some time pas
print("sleeping for 20 seconds ...")
sleep(20)

# check if token still valid
if client.validate_token():
    print("Token is still valid!")
```

If your token is still valid, this function will return `True`.


### Token Refresh
If your token happens to be no longer valid, there are a few paths forward:
- Obtain a new JWT using `set_token`
- Refresh your existing token pair with `refresh_token`

Let's look at both in the example below.

#### Set New Tokens
You can set a new token pair by simply using the `set_token` function. This will use your existing username and password to obtain a new token pair.

```python
client.set_token()
```

This will update the session `Authentication` header with your fresh `access` token and set a new `refresh` token.

#### Refresh Existing Token
You can also refresh your existing `access` token using the `refresh_token` function.

```python
client.refresh_token()
```

This will updated only the session `Authorization` header with your fresh `access` token.

### Existing Valid JWT Authentication
We can also authenticate using an existing valid JWT.

```python
from evrim import Evrim
import os

url = os.getenv("EVRIM_URL")
token = os.getenv("EVRIM_TOKEN")
refresh = os.getenv("EVRIM_REFRESH_TOKEN")  # optional but can be used to refresh existing access token

client = Evrim.from_token(
    url=url,
    token=token,
    refresh=refresh  # optional value but helpful!
)
```

This is will do two things:
- Validate your access token to ensure it is still valid
- If valid, set you session `Authorization` header with the existing valid `access` token
- If `response` is provided, this token will also be set so you can leverage operations like `refresh_token`.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "evrim",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.12",
    "maintainer_email": null,
    "keywords": null,
    "author": "Chris",
    "author_email": "chris@evrim.ai",
    "download_url": "https://files.pythonhosted.org/packages/2b/a2/9aa50529c100b5e1635a7b165a22669433e21a7fc1c1aa339169febdb13b/evrim-0.1.1.tar.gz",
    "platform": null,
    "description": "[![codecov](https://codecov.io/gh/csmizzle/evrim-client/graph/badge.svg?token=E2V35OBJCA)](https://codecov.io/gh/csmizzle/evrim-client)\n\n# Evrim Client\nA simple Python client to interact with Evrim's REST API.\n\n## Authentication\nEvrim's REST API uses [JSON Web Tokens](https://jwt.io/introduction) (JWT) for authentication. Users can either obtain one using their username and password or use an existing **valid** JWT.\n\n### Username/Password Authentication\nLet's start by obtaining a JWT using our username and password. When initializing `Evrim`, the client will authenticate using the provided url, username, and password and obtain a valid JWT.\n\n```python\nfrom evrim import Evrim\nimport os\n\n# access env variables\nurl = os.getenv(\"EVRIM_URL\")\nusername = os.getenv(\"EVRIM_USERNAME\")\npassword = os.getenv(\"EVRIM_PASSWORD\")\n\n# authenticate using url, username, and password\nclient = Evrim(\n    url=url\n    username=username,\n    password=password\n)\n```\n\nIf this authentication is successful, two tokens are then issued to the user:\n- `access`: Bearer token used in all subsequent requests in the `Authorization` header\n- `refresh`: Token used to obtain a new `access` token once it expires\n\n### Token Validation\nJWTs expire after a certain amount of time. To check if your token is still valid, `Evrim` provides the `validate_token` function.\n\n```python\nfrom evrim import Evrim\nfrom time import sleep\nimport os\n\n# access env variables\nurl = os.getenv(\"EVRIM_URL\")\nusername = os.getenv(\"EVRIM_USERNAME\")\npassword = os.getenv(\"EVRIM_PASSWORD\")\n\n# authenticate using url, username, and password\nclient = Evrim(\n    url=url\n    username=username,\n    password=password\n)\n\n# let some time pas\nprint(\"sleeping for 20 seconds ...\")\nsleep(20)\n\n# check if token still valid\nif client.validate_token():\n    print(\"Token is still valid!\")\n```\n\nIf your token is still valid, this function will return `True`.\n\n\n### Token Refresh\nIf your token happens to be no longer valid, there are a few paths forward:\n- Obtain a new JWT using `set_token`\n- Refresh your existing token pair with `refresh_token`\n\nLet's look at both in the example below.\n\n#### Set New Tokens\nYou can set a new token pair by simply using the `set_token` function. This will use your existing username and password to obtain a new token pair.\n\n```python\nclient.set_token()\n```\n\nThis will update the session `Authentication` header with your fresh `access` token and set a new `refresh` token.\n\n#### Refresh Existing Token\nYou can also refresh your existing `access` token using the `refresh_token` function.\n\n```python\nclient.refresh_token()\n```\n\nThis will updated only the session `Authorization` header with your fresh `access` token.\n\n### Existing Valid JWT Authentication\nWe can also authenticate using an existing valid JWT.\n\n```python\nfrom evrim import Evrim\nimport os\n\nurl = os.getenv(\"EVRIM_URL\")\ntoken = os.getenv(\"EVRIM_TOKEN\")\nrefresh = os.getenv(\"EVRIM_REFRESH_TOKEN\")  # optional but can be used to refresh existing access token\n\nclient = Evrim.from_token(\n    url=url,\n    token=token,\n    refresh=refresh  # optional value but helpful!\n)\n```\n\nThis is will do two things:\n- Validate your access token to ensure it is still valid\n- If valid, set you session `Authorization` header with the existing valid `access` token\n- If `response` is provided, this token will also be set so you can leverage operations like `refresh_token`.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Simple client for Evrim",
    "version": "0.1.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9e72061f18eabad0bf8dd83268212e21672ee7ebd0f6997418bdf133af33482b",
                "md5": "53d130b9456aac904a39d910c7d67acb",
                "sha256": "20aebfce88fb38e47260c16d5ed54bb0d4ca092150e1e3fb4ef5030afb360370"
            },
            "downloads": -1,
            "filename": "evrim-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "53d130b9456aac904a39d910c7d67acb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.12",
            "size": 5998,
            "upload_time": "2024-09-15T18:08:55",
            "upload_time_iso_8601": "2024-09-15T18:08:55.188370Z",
            "url": "https://files.pythonhosted.org/packages/9e/72/061f18eabad0bf8dd83268212e21672ee7ebd0f6997418bdf133af33482b/evrim-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2ba29aa50529c100b5e1635a7b165a22669433e21a7fc1c1aa339169febdb13b",
                "md5": "8746539b3df1b4de264cb0746d78b8f1",
                "sha256": "0253d97d24c0147c14a44afadfd5fd3937fc4e69280df67ede24c6df2978369a"
            },
            "downloads": -1,
            "filename": "evrim-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8746539b3df1b4de264cb0746d78b8f1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.12",
            "size": 5202,
            "upload_time": "2024-09-15T18:08:56",
            "upload_time_iso_8601": "2024-09-15T18:08:56.637266Z",
            "url": "https://files.pythonhosted.org/packages/2b/a2/9aa50529c100b5e1635a7b165a22669433e21a7fc1c1aa339169febdb13b/evrim-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-15 18:08:56",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "evrim"
}
        
Elapsed time: 1.09793s