Python Quick-Start
This page aims to give a quick start example on how to use Mind Lake via Python SDK.
Demos on how to connect a lake, create a table, encrypt data, and insert and query encrypted data.
You can check out Python API Reference for more advanced functions.
Preparation
If you need to configure Python local environment, please visit our step-by-step tutorial for Python:
Source Code
'''
Python Quick Start
pip install MindLake
copy env-template.py into env.py and replace with your own details
'''
import env
import mindlakesdk
# 1. connect to MindLake, '5' is example of Goerli Testnet chainID
chainID = '5'
mind = mindlakesdk.connect(env.walletPrivateKeyAlice, env.appKey, chainID)
assert mind, mind.message
# 2. create a table
result = mind.datalake.createTable('test_table_enc',
[
mind.datalake.Column('id', mind.DataType.int4, False),
mind.datalake.Column('token', mind.DataType.text, True)
])
assert result, result.message
# 3. encrypt data
result = mind.cryptor.encrypt('USDT','test_table_enc.token')
assert result, result.message
encryptedTokenName = result.data
# 4. insert encrypted data
result = mind.datalake.query(f"""INSERT INTO test_table_enc (id, token)
VALUES (1, '{encryptedTokenName}')""")
assert result, result.message
# 5. query encrypted data
result = mind.datalake.query("SELECT token FROM test_table_enc")
assert result, result.message
print(result.data['columnList'][0])
for row in result.data['data']:
result = mind.cryptor.decrypt(row[0])
assert result, result.message
print(result.data)
Execution Output
token
USDT
Last updated