Skip to content

Commit 5404364

Browse files
Merge pull request #258 from skyflowapi/release/26.5.1
Public Release/26.5.1
2 parents a42a66d + 5e2cf64 commit 5404364

5 files changed

Lines changed: 269 additions & 4 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Skyflow-python
22

3+
> **Python V2.1.0 IS NOW AVAILABLE:** A new, improved version of the Skyflow SDK is ready with flexible authentication, multi-vault support, builder patterns, and richer error diagnostics. V1 is in maintenance mode (security patches only) and will reach End of Life on October 31, 2026. We recommend upgrading to v2.1.0 — see the **[Migration Guide](docs/migrate_to_v2.md)** for step-by-step instructions.
4+
5+
6+
37
---
48
## Description
59
This Python SDK is designed to help developers easily implement Skyflow into their python backend.

docs/migrate_to_v2.md

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
# Migrate from v1 to v2
2+
3+
This guide outlines the steps required to migrate the Skyflow Python SDK from version 1 (v1) to version 2 (v2).
4+
5+
---
6+
7+
## Breaking Changes from V1 to V2
8+
9+
- **Client initialization**: `Configuration(vaultID, vaultURL, tokenProvider)` passed to `Client()` is replaced by `Credentials` + `VaultConfig` passed to `Skyflow()`.
10+
- **Vault URL**: `vaultURL` is now split into `vaultId` + `clusterId`.
11+
- **Request/response types**: Operations like insert, get, detokenize now use typed request/response objects (e.g. `InsertRequest` / `InsertResponse`) instead of raw `dict`.
12+
- **Error handling**: `SkyflowError` restructured to include `httpStatus`, `details`, and `requestId`.
13+
- **Logging**: Global `set_log_level(LogLevel.X)` replaced by per-instance `logLevel` set on the `Skyflow` client.
14+
- **Import paths**: New module structure across all packages.
15+
16+
---
17+
18+
## Authentication
19+
20+
In v2, multiple authentication options have been introduced. You can now provide credentials in the following ways:
21+
22+
- **Passing credentials in ENV** (`SKYFLOW_CREDENTIALS`) (**Recommended**)
23+
- **API Key**
24+
- **Path to your credentials JSON file**
25+
- **Stringified JSON of your credentials**
26+
- **Bearer token**
27+
28+
These options allow you to choose the authentication method that best suits your use case.
29+
30+
### v1 (Old): Passing the token provider function below as a parameter to the Configuration.
31+
32+
```python
33+
# User defined function to provide access token to the vault apis
34+
def token_provider():
35+
global bearer_token
36+
if not is_expired(bearer_token):
37+
return bearer_token
38+
bearer_token, _ = generate_bearer_token('<YOUR_CREDENTIALS_FILE_PATH>')
39+
return bearer_token
40+
```
41+
42+
#### v2 (New): Passing one of the following:
43+
44+
```python
45+
# Option 1: API Key (Recommended)
46+
credentials = {
47+
'api_key': '<YOUR_API_KEY>', # API key
48+
}
49+
50+
# Option 2: Environment Variables (Recommended)
51+
# Set SKYFLOW_CREDENTIALS in your environment
52+
53+
# Option 3: Credentials File
54+
credentials = {
55+
'path': '<PATH_TO_CREDENTIALS_JSON>', # Path to credentials file
56+
}
57+
58+
# Option 4: Stringified JSON
59+
credentials = {
60+
'credentials_string': '<YOUR_CREDENTIALS_STRING>', # Credentials as string
61+
}
62+
63+
# Option 5: Bearer Token
64+
credentials = {
65+
'token': '<YOUR_BEARER_TOKEN>', # Bearer token
66+
}
67+
```
68+
69+
**Notes:**
70+
- Use only ONE authentication method.
71+
- API Key or Environment Variables are recommended for production use.
72+
- Secure storage of credentials is essential.
73+
74+
### Initializing the client
75+
76+
In v2, we have introduced a Builder design pattern for client initialization and added support for multi-vault. This allows you to configure multiple vaults during client initialization.
77+
78+
During client initialization, you can pass the following parameters:
79+
80+
- **`vault_id`** and **`cluster_id`**: These values are derived from the vault ID & vault URL.
81+
- **`env`**: Specify the environment (e.g., SANDBOX or PROD).
82+
- **`credentials`**: The necessary authentication credentials.
83+
84+
#### v1 (Old):
85+
86+
```python
87+
# Initializing a Skyflow Client instance with a SkyflowConfiguration object
88+
config = Configuration('<VAULT_ID>', '<VAULT_URL>', token_provider)
89+
client = Client(config)
90+
```
91+
92+
#### v2 (New):
93+
94+
```python
95+
# Initializing a Skyflow Client instance
96+
client = (
97+
Skyflow.builder()
98+
.add_vault_config({
99+
'vault_id': '<VAULT_ID>', # Primary vault
100+
'cluster_id': '<CLUSTER_ID>', # ID from your vault URL e.g., https://{clusterId}.vault.skyflowapis.com
101+
'env': Env.PROD, # Env by default it is set to PROD
102+
'credentials': credentials # Individual credentials
103+
})
104+
.add_skyflow_credentials(credentials) # Skyflow credentials will be used if no individual credentials are passed
105+
.set_log_level(LogLevel.INFO) # set log level by default it is set to ERROR
106+
.build()
107+
)
108+
```
109+
110+
**Key Changes:**
111+
- `vault_url` replaced with `cluster_id`.
112+
- Added environment specification (`env`).
113+
- Instance-specific log levels.
114+
115+
### Request & Response Structure
116+
117+
In v2, with the introduction of constructor parameters, you can now pass parameters to `InsertRequest`. This request needs
118+
- **`table_name`**: The name of the table.
119+
- **`values`**: An array of objects containing the data to be inserted.
120+
The response will be of type `InsertResponse` class, which contains `inserted_fields` and errors.
121+
122+
**Note:** Similar patterns apply to other operations like Get, Update, Delete. See the [README](../README.md) for complete examples.
123+
124+
#### v1 (Old): Request Building
125+
126+
```python
127+
client.insert(
128+
{
129+
"records": [
130+
{
131+
"table": "cards",
132+
"fields": {
133+
"cardNumber": "41111111111",
134+
"cvv": "123",
135+
},
136+
}
137+
]
138+
},
139+
InsertOptions(True),
140+
)
141+
```
142+
143+
#### v2 (New): Request Building
144+
145+
```python
146+
from skyflow.vault.data import InsertRequest
147+
148+
# Prepare Insertion Data
149+
insert_data = [
150+
{
151+
'card_number': '<VALUE1>',
152+
'cvv': '<VALUE2>',
153+
},
154+
]
155+
156+
table_name = '<SENSITIVE_DATA_TABLE>' # Replace with your actual table name
157+
158+
# Create Insert Request
159+
insert_request = InsertRequest(
160+
table=table_name,
161+
values=insert_data,
162+
return_tokens=True, # Optional: Get tokens for inserted data
163+
continue_on_error=True # Optional: Continue on partial errors
164+
)
165+
166+
# Perform Secure Insertion
167+
response = skyflow_client.vault('<VAULT_ID>').insert(insert_request)
168+
```
169+
170+
#### v1 (Old): Response Structure
171+
172+
```json
173+
{
174+
"records": [
175+
{
176+
"table": "cards",
177+
"fields": {
178+
"cardNumber": "f3907186-e7e2-466f-91e5-48e12c2bcbc1",
179+
"cvv": "1989cb56-63da-4482-a2df-1f74cd0dd1a5",
180+
"skyflow_id": "d863633c-8c75-44fc-b2ed-2b58162d1117"
181+
},
182+
"request_index": 0
183+
}
184+
]
185+
}
186+
```
187+
188+
#### v2 (New): Response Structure
189+
190+
```python
191+
InsertResponse(
192+
inserted_fields=[
193+
{
194+
'skyflow_id': 'a8f3ed5d-55eb-4f32-bf7e-2dbf4b9d9097',
195+
'card_number': '5479-4229-4622-1393'
196+
}
197+
],
198+
errors=[]
199+
)
200+
```
201+
202+
### Request Options
203+
204+
In v2, we have introduced constructor parameters, allowing you to set options as key-value pairs as parameters in request.
205+
206+
#### v1 (Old):
207+
208+
```python
209+
options = InsertOptions(
210+
tokens = True
211+
)
212+
```
213+
214+
#### v2 (New):
215+
216+
```python
217+
insert_request = InsertRequest(
218+
table=table_name, # Replace with the table name
219+
values=insert_data,
220+
return_tokens=False, # Do not return tokens
221+
continue_on_error=False, # Stop inserting if any record fails
222+
upsert='<UPSERT_COLUMN>', # Replace with the column name used for upsert logic, if any
223+
token_mode=TokenMode.DISABLE, # Disable BYOT
224+
tokens='<TOKENS>' # Set with tokens when TokenMode is ENABLE
225+
)
226+
```
227+
228+
### Error Structure
229+
230+
In v2, we have enriched the error details to provide better debugging capabilities.
231+
The error response now includes:
232+
- **http_status**: The HTTP status code.
233+
- **grpc_code**: The gRPC code associated with the error.
234+
- **details** & **message**: A detailed description of the error.
235+
- **request_id**: A unique request identifier for easier debugging.
236+
237+
#### v1 (Old) Error Structure:
238+
239+
```json
240+
{
241+
"code": "<http_code>",
242+
"message": "<message>"
243+
}
244+
```
245+
246+
#### v2 (New) Error Structure:
247+
248+
```python
249+
{
250+
"http_status": "<http_status>",
251+
"grpc_code": <grpc_code>,
252+
"http_code": <http_code>,
253+
"message": "<message>",
254+
"request_id": "<request_id>",
255+
"details": [ "<details>" ]
256+
}
257+
```

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
if sys.version_info < (3, 7):
88
raise RuntimeError("skyflow requires Python 3.7+")
9-
current_version = '1.15.6'
9+
current_version = '2.1.1.dev0+7b39339'
1010

1111
setup(
1212
name='skyflow',
@@ -16,7 +16,7 @@
1616
packages=find_packages(where='.', exclude=['test*']),
1717
url='https://github.com/skyflowapi/skyflow-python/',
1818
license='LICENSE',
19-
description='Skyflow SDK for the Python programming language',
19+
description='[DEPRECATED - EOL 2026-10-31] Skyflow Python SDK v1.x. Migrate to v2: https://github.com/skyflowapi/skyflow-python/blob/main/docs/migrate_to_v2.md',
2020
long_description=open('README.rst').read(),
2121
install_requires=[
2222
'PyJWT',

skyflow/vault/_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
from skyflow.vault._delete import deleteProcessResponse
1717
from skyflow.vault._query import getQueryRequestBody, getQueryResponse
1818
from skyflow.errors._skyflow_errors import SkyflowError, SkyflowErrorCodes, SkyflowErrorMessages
19-
from skyflow._utils import log_info, log_error, InfoMessages, InterfaceName, getMetrics
19+
from skyflow._utils import log_info, log_error, InfoMessages, InterfaceName, getMetrics, skyflowLog
2020
from skyflow.vault._token import tokenProviderWrapper
2121

2222
class Client:
2323
def __init__(self, config: Configuration):
24+
skyflowLog.warning(
25+
"skyflow-python v1.x is deprecated and will reach End of Life on October 31, 2026. "
26+
"Please migrate to v2: https://github.com/skyflowapi/skyflow-python/blob/main/docs/migrate_to_v2.md"
27+
)
2428

2529
interface = InterfaceName.CLIENT.value
2630

skyflow/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SDK_VERSION = '1.15.6'
1+
SDK_VERSION = '2.1.1.dev0+7b39339'

0 commit comments

Comments
 (0)