For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DocsAPI Reference
  • Fundamentals
    • Home
    • Why Skyflow?
    • Get started with Skyflow
    • Explore what Skyflow can do
    • Authenticate
    • Accounts and environments
    • Deployment models
    • Security best practices
    • Compliance and certifications
    • Get data into Skyflow
    • Platform FAQs
  • Governance
    • Overview
  • Tokenization
    • Overview
  • Connections
    • Overview
  • Processing
  • AI and data sanitization
    • Overview
  • SDKs
    • Overview
      • Go: Migrate from V1 to V2
      • Python: Migrate from V1 to V2
      • Node.js: Migrate from V1 to V2
      • Java: Migrate from V1 to V2
  • Elements
    • Collect and reveal data with Skyflow Elements
LogoLogo
Login
Login
On this page
  • Authentication
  • Initialize the client
  • Insert records
  • Request options
  • Error handling
SDKsOverview

Python SDK: Migrate from V1 to V2

Was this page helpful?
Previous

Node.js SDK: Migrate from V1 to V2

Next
Built with

This guide outlines the steps required to migrate the Skyflow Python SDK from version 1 (v1) to version 2 (v2).

Authentication

V1 required a token provider function. V2 lets you choose from five credential types.

V1:

1def token_provider():
2 global bearer_token
3 if not is_expired(bearer_token):
4 return bearer_token
5 bearer_token, _ = generate_bearer_token('<YOUR_CREDENTIALS_FILE_PATH>')
6 return bearer_token

V2:

1# Option 1: API key (recommended)
2credentials = {
3 'api_key': '<YOUR_API_KEY>',
4}
5
6# Option 2: Environment variable — set SKYFLOW_CREDENTIALS in your environment
7
8# Option 3: Credentials file
9credentials = {
10 'path': '<PATH_TO_CREDENTIALS_JSON>',
11}
12
13# Option 4: Stringified JSON
14credentials = {
15 'credentials_string': '<YOUR_CREDENTIALS_STRING>',
16}
17
18# Option 5: Bearer token
19credentials = {
20 'token': '<YOUR_BEARER_TOKEN>',
21}

Use only one authentication method. API key or environment variables are recommended for production use.

Initialize the client

V2 introduces a builder pattern for client initialization and adds multi-vault support. Log levels are now per-instance instead of global.

V1:

1config = Configuration('<VAULT_ID>', '<VAULT_URL>', token_provider)
2client = Client(config)

V2:

1client = (
2 Skyflow.builder()
3 .add_vault_config({
4 'vault_id': '<VAULT_ID>',
5 'cluster_id': '<CLUSTER_ID>', # ID from your vault URL e.g., https://{clusterId}.vault.skyflowapis.com
6 'env': Env.PROD,
7 'credentials': credentials
8 })
9 .add_skyflow_credentials(credentials) # Used if no individual vault credentials are set
10 .set_log_level(LogLevel.INFO)
11 .build()
12)

Key changes:

  • vault_url replaced with cluster_id
  • env is now required (Env.PROD, Env.SANDBOX)
  • Log level is set per client instance

Insert records

V2 uses constructor parameters for InsertRequest instead of a plain dict. Responses use typed classes.

V1:

1client.insert(
2 {
3 "records": [
4 {
5 "table": "cards",
6 "fields": {
7 "cardNumber": "41111111111",
8 "cvv": "123",
9 },
10 }
11 ]
12 },
13 InsertOptions(True),
14)

V2:

1from skyflow.vault.data import InsertRequest
2
3insert_data = [
4 {
5 'card_number': '<VALUE1>',
6 'cvv': '<VALUE2>',
7 },
8]
9
10insert_request = InsertRequest(
11 table='<SENSITIVE_DATA_TABLE>',
12 values=insert_data,
13 return_tokens=True,
14 continue_on_error=True
15)
16
17response = skyflow_client.vault('<VAULT_ID>').insert(insert_request)

V1 response:

1{
2 "records": [
3 {
4 "table": "cards",
5 "fields": {
6 "cardNumber": "f3907186-e7e2-466f-91e5-48e12c2bcbc1",
7 "cvv": "1989cb56-63da-4482-a2df-1f74cd0dd1a5",
8 "skyflow_id": "d863633c-8c75-44fc-b2ed-2b58162d1117"
9 },
10 "request_index": 0
11 }
12 ]
13}

V2 response:

1InsertResponse(
2 inserted_fields=[
3 {
4 'skyflow_id': 'a8f3ed5d-55eb-4f32-bf7e-2dbf4b9d9097',
5 'card_number': '5479-4229-4622-1393'
6 }
7 ],
8 errors=[]
9)

Request options

V2 uses constructor parameters on InsertRequest instead of a separate InsertOptions object.

V1:

1options = InsertOptions(
2 tokens=True
3)

V2:

1insert_request = InsertRequest(
2 table=table_name,
3 values=insert_data,
4 return_tokens=False,
5 continue_on_error=False,
6 upsert='<UPSERT_COLUMN>',
7 token_mode=TokenMode.DISABLE,
8 tokens='<TOKENS>'
9)

Error handling

V2 errors include more detail to help with debugging.

V1:

1{
2 "code": "<http_code>",
3 "message": "<message>"
4}

V2:

1{
2 "http_status": "<http_status>",
3 "grpc_code": "<grpc_code>",
4 "http_code": "<http_code>",
5 "message": "<message>",
6 "request_id": "<request_id>",
7 "details": ["<details>"]
8}

Use the request_id field when contacting Skyflow support — it uniquely identifies the request for faster diagnosis.