Skip to content

Commit 1a63eb0

Browse files
authored
Merge pull request #249 from fastlabel/feature/construct-api-with-token
API キーを Client の初期化時に渡せるように修正
2 parents 76d9c3d + 65a3beb commit 1a63eb0

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ import fastlabel
6161
client = fastlabel.Client()
6262
```
6363

64+
Or initialize with API Key directly.
65+
66+
```python
67+
import fastlabel
68+
client = fastlabel.Client("YOUR_ACCESS_TOKEN")
69+
```
70+
6471
### Limitation
6572

6673
API is allowed to call 10000 times per 10 minutes. If you create/delete a large size of tasks, please wait a second for every requests.

fastlabel/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
class Client:
4242
api = None
4343

44-
def __init__(self):
45-
self.api = Api()
44+
def __init__(self, access_token: Optional[str] = None):
45+
self.api = Api(access_token=access_token)
4646

4747
# Task Find
4848

fastlabel/api.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from typing import Union
2+
from typing import Optional, Union
33

44
import requests
55

@@ -11,12 +11,13 @@ class Api:
1111

1212
access_token = None
1313

14-
def __init__(self):
15-
if os.environ.get("FASTLABEL_API_URL"):
16-
self.base_url = os.environ.get("FASTLABEL_API_URL")
17-
if not os.environ.get("FASTLABEL_ACCESS_TOKEN"):
14+
def __init__(self, access_token: Optional[str] = None):
15+
if api_url := os.environ.get("FASTLABEL_API_URL"):
16+
self.base_url = api_url
17+
access_token = access_token or os.environ.get("FASTLABEL_ACCESS_TOKEN")
18+
if not access_token:
1819
raise ValueError("FASTLABEL_ACCESS_TOKEN is not configured.")
19-
self.access_token = "Bearer " + os.environ.get("FASTLABEL_ACCESS_TOKEN")
20+
self.access_token = "Bearer " + access_token
2021

2122
def get_request(self, endpoint: str, params=None) -> Union[dict, list]:
2223
"""Makes a get request to an endpoint.

0 commit comments

Comments
 (0)