-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from skyflowapi/SK-815-update-readme-and-chang…
…elog-add-options-tokens-support-for-get-methods-in-python-SDK SK-815 update readme and changelog add options tokens support for get…
- Loading branch information
Showing
1 changed file
with
1 addition
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,7 @@ This Python SDK is designed to help developers easily implement Skyflow into the | |
- [Invoke Connection](#invoke-connection) | ||
- [Logging](#logging) | ||
- [Reporting a Vulnerability](#reporting-a-vulnerability) | ||
- [Get](#get-1) | ||
- [Update](#update-1) | ||
|
||
|
||
## Features | ||
|
||
|
@@ -722,199 +721,3 @@ Current the following 5 log levels are supported: | |
## Reporting a Vulnerability | ||
|
||
If you discover a potential security issue in this project, please reach out to us at [email protected]. Please do not create public GitHub issues or Pull Requests, as malicious actors could potentially view them. | ||
|
||
### Get | ||
|
||
To retrieve data using Skyflow IDs or unique column values, use the `get(records: dict)` method. The `records` parameter takes a Dictionary that contains either an array of Skyflow IDs or a unique column name and values. | ||
|
||
Note: You can use either Skyflow IDs or `unique` values to retrieve records. You can't use both at the same time. | ||
|
||
```python | ||
{ | ||
'records': [ | ||
{ | ||
'columnName': str, # Name of the unique column. | ||
'columnValues': [str], # List of unique column values. | ||
'table': str, # Name of table holding the data. | ||
'redaction': Skyflow.RedactionType, # Redaction applied to retrieved data. | ||
} | ||
] | ||
} | ||
or | ||
{ | ||
'records': [ | ||
{ | ||
'ids': [str], # List of Skyflow IDs. | ||
'table': str, # Name of table holding the data. | ||
'redaction': Skyflow.RedactionType, # Redaction applied to retrieved data. | ||
} | ||
] | ||
} | ||
|
||
``` | ||
Sample usage | ||
|
||
The following snippet shows how to use the `get()` method. For details, see [get_sample.py].(https://github.com/skyflowapi/skyflow-python/blob/main/samples/get_sample.py), | ||
|
||
```python | ||
from skyflow.vault import RedactionType | ||
|
||
skyflowIDs = ['f8d8a622-b557-4c6b-a12c-c5ebe0b0bfd9'] | ||
record = {'ids': skyflowIDs, 'table': 'cards', 'redaction':RedactionType.PLAIN_TEXT} | ||
recordsWithUniqueColumn = | ||
{ | ||
'table': 'test_table', | ||
'columnName': 'card_number', | ||
'columnValues': ['123456'], | ||
'redaction': RedactionType.PLAIN_TEXT | ||
} | ||
|
||
invalidID = ['invalid skyflow ID'] | ||
badRecord = {'ids': invalidID, 'table': 'cards', 'redaction': RedactionType.PLAIN_TEXT} | ||
|
||
records = {'records': [record, badRecord]} | ||
|
||
try: | ||
client.get(records) | ||
except SkyflowError as e: | ||
if e.data: | ||
print(e.data) | ||
else: | ||
print(e) | ||
``` | ||
|
||
Sample response: | ||
|
||
```python | ||
{ | ||
'records': [ | ||
{ | ||
'fields': { | ||
'card_number': '4111111111111111', | ||
'cvv': '127', | ||
'expiry_date': '11/35', | ||
'fullname': 'monica', | ||
'skyflow_id': 'f8d8a622-b557-4c6b-a12c-c5ebe0b0bfd9' | ||
}, | ||
'table': 'cards' | ||
}, | ||
{ | ||
'fields': { | ||
'card_number': '123456', | ||
'cvv': '317', | ||
'expiry_date': '10/23', | ||
'fullname': 'sam', | ||
'skyflow_id': 'da26de53-95d5-4bdb-99db-8d8c66a35ff9' | ||
}, | ||
'table': 'cards' | ||
} | ||
], | ||
'errors': [ | ||
{ | ||
'error': { | ||
'code': '404', | ||
'description': 'No Records Found' | ||
}, | ||
'skyflow_ids': ['invalid skyflow id'] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### Update | ||
|
||
To update data in your vault, use the `update(records: dict, options: UpdateOptions)` method. The `records` parameter takes a Dictionary that contains records to fetch. If `UpdateTokens` is `True`, Skyflow returns tokens for the record you just updated. If `, ids if `UpdateOptions` is `False`, Skyflow returns IDs for the record you updated. | ||
|
||
```python | ||
# Optional, indicates whether to return all fields for updated data. Defaults to 'true'. | ||
options: UpdateOptions | ||
``` | ||
|
||
```python | ||
{ | ||
'records': [ | ||
{ | ||
'id': str, # Skyflow ID of the record to be updated. | ||
'table': str, # Name of table holding the skyflowID. | ||
'fields': { | ||
str: str # Name of the column and value to update. | ||
} | ||
} | ||
] | ||
} | ||
``` | ||
Sample usage | ||
|
||
The following snippet shows how to use the `update()` method. For details, see [update_sample.py](https://github.com/skyflowapi/skyflow-python/blob/main/samples/update_sample.py), | ||
|
||
```python | ||
records = { | ||
'records': [ | ||
{ | ||
'id': '56513264-fc45-41fa-9cb0-d1ad3602bc49', | ||
'table': 'cards', | ||
'fields': { | ||
'card_number': '45678910234' | ||
} | ||
} | ||
] | ||
} | ||
try: | ||
client.update(records, UpdateOptions(True)) | ||
except SkyflowError as e: | ||
if e.data: | ||
print(e.data) | ||
else: | ||
print(e) | ||
``` | ||
|
||
Sample response | ||
|
||
`UpdateOptions` set to `True` | ||
|
||
```python | ||
{ | ||
'records':[ | ||
{ | ||
'id':'56513264-fc45-41fa-9cb0-d1ad3602bc49', | ||
'fields':{ | ||
'card_number':'0051-6502-5704-9879' | ||
} | ||
} | ||
], | ||
'errors':[] | ||
} | ||
``` | ||
|
||
`UpdateOptions` set to `False` | ||
|
||
```python | ||
{ | ||
'records':[ | ||
{ | ||
'id':'56513264-fc45-41fa-9cb0-d1ad3602bc49' | ||
} | ||
], | ||
'errors':[] | ||
} | ||
``` | ||
|
||
Sample Error | ||
|
||
```python | ||
{ | ||
'records':[ | ||
{ | ||
'id':'56513264-fc45-41fa-9cb0-d1ad3602bc49' | ||
} | ||
], | ||
'errors':[ | ||
{ | ||
'error':{ | ||
'code':404, | ||
'description':'Token for skyflowID doesn"t exist in vault - Request ID: a8def196-9569-9cb7-9974-f899f9e4bd0a' | ||
} | ||
} | ||
] | ||
} | ||
``` |