# Python Script Example

## Usage Requirement

* This feature will only work in a [**team workspace**](https://docs.datasaur.ai/workspace-management/workspace).
* Ensure pip3 and the python3 CLI are installed on the machine.

## Installation

1. Download or clone this [repository](https://github.com/datasaur-ai/api-client-example) and go to the directory.
2. Run `pip3 install -r requirements.txt`.

## Guide

#### 1. Generate your OAuth credentials

The instructions can be found [here](https://docs.datasaur.ai/api/credentials). Save the credentials securely, we will use it for the next step.

#### 2. Set up a project via Custom Project

We have five steps here. Set up your project until reaching Step 5 (Project Settings). Ensure all desired project configurations are properly set.

#### 3. In the Step 5, click “View Script” in the top right corner

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-2062cd82d0c199bd20f68a415fe25771227db1fa%2Fimage.png?alt=media&#x26;token=242dc643-a4f4-469e-bedb-37434fe967c8" alt=""><figcaption><p>Figure 1: Step 5 of Project Creation Wizard Default UI</p></figcaption></figure>

**4. Copy the configuration by clicking the icon on the top right corner of the UI**

<figure><img src="https://448889121-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MbjY0HseEqu7LtYAt4d%2Fuploads%2Fgit-blob-77c70eed5f0d42ee4082caf908508a7a7aae9c37%2Fimage%20(1).png?alt=media&#x26;token=a8c14fe8-074d-46cb-9b4b-d31c59d3d5c6" alt=""><figcaption><p>Figure 2: Step 5 of Project Creation Wizard View Script</p></figcaption></figure>

#### 5. Paste the configuration to create\_project.json

The file is located in the `api-client-example/create-project-async` folder.

#### 6. Insert your dataset for the project in the `api-client-example/create-project-async/documents` folder

All files inside the folder will be treated as the project's documents. Make sure you remove any files that don't belong to the project.

#### 7. Run the command on your terminal to create the project

Navigate to `api-client-example/create-project-async` first before running the command. Note that this API only submits a job, not a synchronous process. Thus, we need to make sure whether the job is successful which will be covered in the next step.

```python
python3 api_client.py create_project \
  --base_url https://app.datasaur.ai \
  --client_id YOUR_CLIENT_ID \
  --client_secret YOUR_CLIENT_SECRET \
  --team_id YOUR_TEAM_ID
 
# for windows replace \ with ^
```

#### 8. Run this command to track your project creation status

The `job_id` will be provided in the previous step along with the full command in the response. The detailed of this API could be seen [here](https://docs.datasaur.ai/api/get-data/check-job).

```bash
python3 api_client.py get_job_status \
  --base_url https://app.datasaur.ai \
  --client_id YOUR_CLIENT_ID \
  --client_secret YOUR_CLIENT_SECRET \
  --job_id YOUR_JOB_ID
 
# for windows replace \ with ^ 
```

With these instructions, you can successfully create a new project by using a Python script via API.
