Skip to content

Commit 3f2016f

Browse files
Johannes HötterJohannes Hötter
authored andcommitted
version 0.0.3
1 parent 0f0d97b commit 3f2016f

File tree

3 files changed

+52
-33
lines changed

3 files changed

+52
-33
lines changed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
![kern-python](https://uploads-ssl.webflow.com/61e47fafb12bd56b40022a49/62766400bd3c57b579d289bf_kern-python%20Banner.png)
22
[![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)](https://www.python.org/downloads/release/python-390/)
3-
[![pypi 0.0.1](https://img.shields.io/badge/pypi-0.0.1-yellow.svg)](https://pypi.org/project/kern-python-client/0.0.1/)
3+
[![pypi 0.0.3](https://img.shields.io/badge/pypi-0.0.3-yellow.svg)](https://pypi.org/project/kern-sdk/0.0.3/)
44

55
# Kern AI API for Python
66

77
This is the official Python SDK for Kern AI, your IDE for programmatic data enrichment and management.
88

99
## Installation
1010

11-
You can set up this library via either running `$ pip install kern-sdk`, or via cloning this repository and running `$ pip install -r requirements.txt` in your repository.
11+
You can set up this library via either running `$ pip install kern-sdk`, or via cloning this repository and running `$ pip install -r requirements.txt` in this repository.
1212

1313
## Usage
1414
Once you installed the package, you can access the application from any Python terminal as follows:
@@ -25,11 +25,23 @@ client = Client(username, password, project_id)
2525
# client = Client(username, password, project_id, uri="http://localhost:4455")
2626
```
2727

28+
Alternatively, you can provide a `secrets.json` file in your repository, looking as follows:
29+
```json
30+
{
31+
"user_name": "your-username",
32+
"password": "your-password",
33+
"project_id": "your-project-id"
34+
}
35+
```
36+
Again, if you run on your local machine, you should provide also `"uri": "http://localhost:4455"`.
37+
2838
Now, you can easily fetch the data from your project:
2939
```python
30-
df = client.fetch_export()
40+
df = client.get_record_export()
3141
```
3242

43+
Alternatively, you can also just run `kern pull` in your CLI given that you have provided the `secrets.json` file.
44+
3345
The `df` contains data of the following scheme:
3446
- all your record attributes are stored as columns, e.g. `headline` or `running_id` if you uploaded records like `{"headline": "some text", "running_id": 1234}`
3547
- per labeling task three columns:
@@ -41,7 +53,8 @@ With the `client`, you easily integrate your data into any kind of system; may i
4153

4254
## Roadmap
4355
- [ ] Register information sources via wrappers
44-
- [ ] Fetch project statistics
56+
- [ ] Add project upload
57+
- [x] Fetch project statistics
4558

4659

4760
If you want to have something added, feel free to open an [issue](https://github.com/code-kern-ai/kern-python/issues).

kern/__init__.py

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from wasabi import msg
44
import pandas as pd
55
from kern import authentication, api_calls, settings, exceptions
6-
from typing import Optional
6+
from typing import Optional, Dict
77
import json
88

99

@@ -35,7 +35,7 @@ def __init__(
3535
self.project_id = project_id
3636

3737
@classmethod
38-
def from_secrets_file(cls, path_to_file):
38+
def from_secrets_file(cls, path_to_file: str):
3939
with open(path_to_file, "r") as file:
4040
content = json.load(file)
4141
uri = content.get("uri")
@@ -48,7 +48,12 @@ def from_secrets_file(cls, path_to_file):
4848
uri=uri,
4949
)
5050

51-
def get_project_details(self):
51+
def get_project_details(self) -> Dict[str, str]:
52+
"""Collect high-level information about your project: name, description, and tokenizer
53+
54+
Returns:
55+
Dict[str, str]: dictionary containing the above information
56+
"""
5257
url = settings.get_project_url(self.project_id)
5358
api_response = api_calls.get_request(url, self.session_token)
5459
return api_response
@@ -62,7 +67,7 @@ def get_record_export(
6267
num_samples (Optional[int], optional): If set, only the first `num_samples` records are collected. Defaults to None.
6368
6469
Returns:
65-
pd.DataFrame: DataFrame containing your record data. For more details, see https://docs.kern.ai
70+
pd.DataFrame: DataFrame containing your record data.
6671
"""
6772
url = settings.get_export_url(self.project_id)
6873
api_response = api_calls.get_request(
@@ -74,29 +79,30 @@ def get_record_export(
7479
msg.good(f"Downloaded export to {download_to}")
7580
return df
7681

77-
def post_file_import(self, upload_from: str):
78-
upload_from = f"{upload_from}_SCALE"
79-
file_type = "records"
80-
import_file_options = None
81-
config_url = settings.get_config_url()
82-
config_api_response = api_calls.get_request(config_url, self.session_token)
83-
endpoint = config_api_response["KERN_S3_ENDPOINT"]
84-
85-
import_url = settings.get_import_url(self.project_id)
86-
import_api_response = api_calls.post_request(
87-
import_url,
88-
{
89-
"file_name": upload_from,
90-
"file_type": file_type,
91-
"import_file_options": import_file_options,
92-
},
93-
self.session_token,
94-
)
82+
# TODO: issue #6
83+
# def post_file_import(self, upload_from: str):
84+
# upload_from = f"{upload_from}_SCALE"
85+
# file_type = "records"
86+
# import_file_options = None
87+
# config_url = settings.get_config_url()
88+
# config_api_response = api_calls.get_request(config_url, self.session_token)
89+
# endpoint = config_api_response["KERN_S3_ENDPOINT"]
90+
91+
# import_url = settings.get_import_url(self.project_id)
92+
# import_api_response = api_calls.post_request(
93+
# import_url,
94+
# {
95+
# "file_name": upload_from,
96+
# "file_type": file_type,
97+
# "import_file_options": import_file_options,
98+
# },
99+
# self.session_token,
100+
# )
95101

96-
credentials = import_api_response["Credentials"]
97-
access_key = credentials["AccessKeyId"]
98-
secret_key = credentials["SecretAccessKey"]
99-
session_token = credentials["SessionToken"]
102+
# credentials = import_api_response["Credentials"]
103+
# access_key = credentials["AccessKeyId"]
104+
# secret_key = credentials["SecretAccessKey"]
105+
# session_token = credentials["SessionToken"]
100106

101-
upload_task_id = import_api_response["uploadTaskId"]
102-
return endpoint, access_key, secret_key, session_token, upload_task_id
107+
# upload_task_id = import_api_response["uploadTaskId"]
108+
# return endpoint, access_key, secret_key, session_token, upload_task_id

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name="kern-sdk",
13-
version="0.0.2",
13+
version="0.0.3",
1414
author="jhoetter",
1515
author_email="johannes.hoetter@kern.ai",
1616
description="Official SDK for the Kern AI API",

0 commit comments

Comments
 (0)