Skip to content

Commit a3ab266

Browse files
SK-2707: add samples guide and fix misleading async sample
- Rename deidentify_file_async.py -> deidentify_file_concurrent.py and clarify it uses thread-based concurrency, not asyncio (SDK is sync-only). - Add samples/README.md (prerequisites, how to run, per-sample index) and samples/.env.example for collecting vault values. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8f155bd commit a3ab266

3 files changed

Lines changed: 122 additions & 6 deletions

File tree

samples/.env.example

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copy this file to `.env` in the samples directory and fill in your values:
2+
# cp .env.example .env
3+
#
4+
# These are the values the samples need. Most samples currently use inline
5+
# <PLACEHOLDER> strings — replace those placeholders with your values, or load
6+
# them from this file using python-dotenv (see samples/README.md).
7+
#
8+
# Do NOT commit your filled-in .env or any real credentials.
9+
10+
# --- Vault connection ---
11+
SKYFLOW_VAULT_ID=<YOUR_VAULT_ID>
12+
SKYFLOW_CLUSTER_ID=<YOUR_CLUSTER_ID> # first segment of https://{cluster_id}.vault.skyflowapis.com
13+
SKYFLOW_ENV=PROD # PROD | SANDBOX | DEV | STAGE
14+
15+
# --- Authentication (provide ONE) ---
16+
SKYFLOW_API_KEY=<YOUR_API_KEY>
17+
# SKYFLOW_BEARER_TOKEN=<YOUR_BEARER_TOKEN>
18+
# SKYFLOW_CREDENTIALS_PATH=/path/to/credentials.json
19+
# SKYFLOW_CREDENTIALS=<YOUR_CREDENTIALS_JSON_STRING>
20+
21+
# --- Vault data samples ---
22+
SKYFLOW_TABLE=table1
23+
24+
# --- Connection samples ---
25+
# SKYFLOW_CONNECTION_ID=<YOUR_CONNECTION_ID>
26+
# SKYFLOW_CONNECTION_URL=<YOUR_CONNECTION_URL>
27+
28+
# --- Detect file samples ---
29+
# SKYFLOW_FILE_PATH=/path/to/file.pdf
30+
# SKYFLOW_OUTPUT_DIR=/path/to/output

samples/README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Skyflow Python SDK — Samples
2+
3+
Runnable examples for the Skyflow Python SDK, grouped by area. Start with the [README](../README.md) and [API Reference](../docs/api_reference.md) for full documentation.
4+
5+
## Prerequisites
6+
7+
- Python 3.9 or above
8+
- The SDK installed: `pip install skyflow`
9+
- A Skyflow account, a vault, and a service account (see [Before you begin](../README.md#before-you-begin))
10+
- The values listed in [`.env.example`](.env.example): `vault_id`, `cluster_id`, `env`, and one credential (API key, bearer token, or service-account credentials)
11+
12+
## Configure
13+
14+
Copy the env template and fill in your values:
15+
16+
```bash
17+
cp .env.example .env
18+
```
19+
20+
The samples ship with inline `<PLACEHOLDER>` strings (for example `<YOUR_VAULT_ID>`). You can either:
21+
22+
1. **Replace the placeholders** directly in the sample file you want to run, or
23+
2. **Load from `.env`** by adding the following near the top of the sample (`python-dotenv` is already a SDK dependency):
24+
25+
```python
26+
import os
27+
from dotenv import load_dotenv
28+
29+
load_dotenv()
30+
vault_id = os.getenv('SKYFLOW_VAULT_ID')
31+
# ...use os.getenv(...) for the other values
32+
```
33+
34+
> Never commit a filled-in `.env` or any real credentials.
35+
36+
## Run a sample
37+
38+
```bash
39+
python samples/vault_api/insert_records.py
40+
```
41+
42+
## What's here
43+
44+
### `vault_api/`
45+
Core vault data operations.
46+
47+
| Sample | Demonstrates |
48+
|--------|--------------|
49+
| `client_operations.py` | Building and managing the Skyflow client |
50+
| `credentials_options.py` | The different credential types |
51+
| `insert_records.py` | Inserting and tokenizing records (`continue_on_error`) |
52+
| `insert_byot.py` | Bring-your-own-token inserts |
53+
| `get_records.py` | Getting records by Skyflow ID |
54+
| `get_column_values.py` | Getting records by column name/values |
55+
| `update_record.py` | Updating a record |
56+
| `delete_records.py` | Deleting records |
57+
| `query_records.py` | SQL queries |
58+
| `detokenize_records.py` | Detokenizing tokens |
59+
| `tokenize_records.py` | Retrieving existing tokens |
60+
| `upload_file.py` | Uploading a file to a record |
61+
| `invoke_connection.py` | Invoking a Skyflow Connection |
62+
63+
### `detect_api/`
64+
Skyflow Detect (de-identification / re-identification).
65+
66+
| Sample | Demonstrates |
67+
|--------|--------------|
68+
| `deidentify_text.py` | De-identifying text |
69+
| `reidentify_text.py` | Re-identifying text |
70+
| `deidentify_file.py` | De-identifying a file |
71+
| `deidentify_file_concurrent.py` | Running a file de-identification on a background thread (thread-based concurrency, not asyncio) |
72+
| `get_detect_run.py` | Polling a file de-identification run by `run_id` |
73+
74+
### `service_account/`
75+
Bearer-token and signed-data-token generation.
76+
77+
| Sample | Demonstrates |
78+
|--------|--------------|
79+
| `token_generation_example.py` | Generating a bearer token |
80+
| `scoped_token_generation_example.py` | Tokens scoped to specific roles |
81+
| `token_generation_with_context_example.py` | Tokens with context (`ctx`) |
82+
| `signed_token_generation_example.py` | Signed data tokens |
83+
| `bearer_token_expiry_example.py` | Handling token expiry / regeneration |

samples/detect_api/deidentify_file_concurrent.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
from concurrent.futures import ThreadPoolExecutor
1313

1414
"""
15-
* Skyflow Deidentify File Example
16-
*
17-
* This sample demonstrates how to use all available options for deidentifying files
18-
* using an asynchronous approach.
19-
* Supported file types: images (jpg, png, etc.), pdf, audio (mp3, wav), documents,
15+
* Skyflow Deidentify File Example (concurrent)
16+
*
17+
* This sample demonstrates how to use all available options for deidentifying files.
18+
* The SDK is synchronous; this example runs the (blocking) deidentify_file call on a
19+
* background thread using concurrent.futures.ThreadPoolExecutor so the main thread can
20+
* continue working. This is thread-based concurrency, not asyncio — the SDK does not
21+
* expose async/await coroutines.
22+
* Supported file types: images (jpg, png, etc.), pdf, audio (mp3, wav), documents,
2023
* spreadsheets, presentations, structured text.
2124
"""
2225

23-
def perform_file_deidentification_async():
26+
def perform_file_deidentification_concurrent():
2427
try:
2528
# Step 1: Configure Credentials
2629
credentials = {

0 commit comments

Comments
 (0)