diff --git a/README.md b/README.md index 534d8a9..bf176ec 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ except SkyflowError as e: ``` + [Example using credentials string](https://github.com/skyflowapi/skyflow-python/blob/main/samples/generate_bearer_token_from_creds_sample.py): ```python @@ -100,8 +101,7 @@ def token_provider(): if is_expired(bearerToken): bearerToken, tokenType = generate_bearer_token_from_creds( credentials=jsonString) - - return bearerToken + return bearerToken, tokenType try: accessToken, tokenType = token_provider() diff --git a/samples/README.md b/samples/README.md index 6354991..597e19e 100644 --- a/samples/README.md +++ b/samples/README.md @@ -1,13 +1,162 @@ -## Description -These are the samples for skyflow-python. In order to use these samples, you must first: +# Python SDK samples -1. Install skyflow module using pip -2. Replace placeholders like ``, `` etc. in the sample file with your Vault ID, Vault URL etc. +Test the SDK by adding `VAULT-ID`, `VAULT-URL`, and `SERVICE-ACCOUNT` details in +the required places for each sample. -Below is a brief description of the samples: +## Prerequisites +- A Skyflow account. If you don't have one, register for one on the + [Try Skyflow](https://skyflow.com/try-skyflow) page. +- Python 3.7.0 or higher. -- [sa_token_sample.py](https://github.com/skyflowapi/skyflow-python/blob/main/samples/sa_token_sample.py): Contains a python program illustrating the usage of `service_account.generate_bearer_token()` -- [insert_sample.py](https://github.com/skyflowapi/skyflow-python/blob/main/samples/insert_sample.py) : Contains a python program illustrating the use of `vault.Client.insert()` -- [detokenize_sample.py](https://github.com/skyflowapi/skyflow-python/blob/main/samples/detokenize_sample.py): Contains a python program illustrating the use of `vault.detokenize()` -- [`get_by_ids_sample.py`](https://github.com/skyflowapi/skyflow-python/blob/main/samples/get_by_ids_sample.py): Contains a python program illustrating the use of `vault.Client.get_by_id()` -- [`invoke_connection_sample.py`](https://github.com/skyflowapi/skyflow-python/blob/main/samples/invoke_connection_sample.py): Contains a python program illustrating the use of `vault.Client.invoke_connection()` \ No newline at end of file +## Prepare + +### Install the Python SDK + +```bash +pip install skyflow +``` + +### Create the vault + +1. In a browser, sign in to Skyflow Studio. +2. Create a vault by clicking **Create Vault** > **Start With a Template** > + **Quickstart vault**. +3. Once the vault is ready, click the gear icon and select **Edit Vault Details**. +4. Note your **Vault URL** and **Vault ID** values, then click **Cancel**. + You'll need these later. + +### Create a service account + +1. In the side navigation click, **IAM** > **Service Accounts** > **New Service Account**. +2. For **Name**, enter "SDK Sample". For **Roles**, choose **Vault Editor**. +3. Click **Create**. Your browser downloads a **credentials.json** file. Keep + this file secure, as You'll need it for each of the samples. + +## The samples + +### [Get data by ID](./getByIDSample.py) + +Get data using Skyflow IDs for the desired records. + +#### Configure + +Replace the following values in the sample file: + +| Value | Description | +| ------------------------------ | ------------------------------------------------------- | +| `` | ID of your vault. | +| `` | URL of your vault. | +| `` | Skyflow ID of the first record. | +| `` | Skyflow ID of the second record. | +| `` | Skyflow ID of the third record. | +| `` | relative path to your service account credentials file. | +| `` | Name of the table to get data from. | + +#### Run the sample + +```bash +python3 getByIDSample.py +``` + +### [Insert data](./InsertSample.py) + +Insert data in the vault. + +#### Configure + +Replace the following values in the sample file: + +| Value | Description | +| ------------------------------ | ------------------------------------------------------- | +| `` | ID of your vault. | +| `` | URL of your vault. | +| `` | relative path to your service account credentials file. | +| `` | Name of the table to insert data into. | +| `` | Name of the column to insert data into. | +| `` | Valid value to insert into the corresponding column. | + +#### Run the sample + +```bash +python3 InsertSample.py +``` + +### [Detokenize data](./detokenizeSample.py) + +Detokenize a data token from the vault. Make sure the specified token is for +data that exists in the vault. If you need a valid token, use +[insert_sample.py](insert_sample.py) to insert the data, then use this data's +token for detokenization. + +#### Configure + +Replace the following values in the sample file: + +| Value | Description | +| ------------------------------ | ------------------------------------------------------- | +| `` | ID of your vault. | +| `` | URL of your vault. | +| `` | relative path to your service account credentials file. | +| `` | Name of the column to insert data into. | +| `` | Token for the data you want to detokenize. | + +#### Run the sample + +```bash +python3 detokenizeSample.py +``` + +### [Invoke a connection](./invokeConnectionSample.py) + +Skyflow Connections is a gateway service that uses Skyflow's underlying +tokenization capabilities to securely connect to first-party and third-party +services. This way, your infrastructure is never directly exposed to sensitive +data, and you offload security and compliance requirements to Skyflow. + +#### Configure + +Replace the following values in the sample file: + +| Value | Description | +| ------------------------------ | ------------------------------------------------------- | +| `` | ID of your vault. | +| `` | URL of your vault. | +| `` | relative path to your service account credentials file. | +| `` | URL of your connection. | +| `` | Access token for your connection. | +| `requestBody` | Your request body content. | +| `pathParams` | Your path parameters. | + +#### Run the sample + +```bash +python3 invokeConnectionSample.py +``` + +### [Service account token generation](./SATokenSample.py) + +Generates SA Token using path of credentials file. + +#### Configure + +Replace `` with the relative path to your service account credentials file. + +#### Run the sample + +```bash +python3 SATokenSample.py +``` + +### [Generate Bearer Token](./generateBearerTokenFromCredsSample.py) + +Generates SA Token using json content of credentials file. + +#### Configure + +Replace `credentials` with the content of service account credentials file. + +#### Run the sample + +```bash +python3 generateBearerTokenFromCredsSample.py +```