Bluzelle-Py是一个Python库,可用于访问Bluzelle数据库服务。
Python库尚未在任何软件包管理器上发布,要安装和使用以下说明:
$ # build the library
$ pip install " poetry==1.1.7 "
$ poetry config virtualenvs.create false
$ poetry install --no-interaction --no-ansi
$ pip install .有一个GitHub操作将新版本(使用新标签)部署到PYPI软件包。 (需要从https://pypi.org网站获取PYPI_TOKEN并将其添加到GitHub存储库秘密中。)
要将您的实例连接到Bluzelle TestNet,您可以:
通过访问https://client.sentry.testnet.private.bluzelle.com:1317/mint来造成帐户,该帐户将提供助记符和地址。这可能需要一段时间。
在https://client.sentry.testnet.private.bluzelle.com:1317/bank/balances/ {address/ {address}上查看您的余额。如果您的帐户余额为0,则造成另一个帐户,直到阳性余额显示
使用以下选项配置您的SDK实例:
from bluzelle . sdk . bluzelle import Bluzelle
sdk = Bluzelle (
mnemonic = "space dilemma domain payment snap crouch arrange"
" fantasy draft shaft fitness rain habit dynamic tip "
"faith mushroom please power kick impulse logic wet cricket" ,
host = "https://client.sentry.testnet.private.bluzelle.com" ,
port = 26657 ,
max_gas = 100000000 ,
gas_price = 0.002 ,
)注意:如果指定的GASPRICE和/或MAXGA太低,则任何交易可能会被验证器拒绝(例如,交易需要的气体比指定的MaxGas多,或者GASPRICE太低而无法覆盖验证者费用)。上述这些字段的默认建议就足够了。
注意:如果要在库文件夹中运行示例,请将代码放在root目录中的文件中
注意:对于两个版本,首先创建一个SDK实例,然后使用Asyncio循环运行程序。有关此有关的更多详细信息,请参见示例/示例.py。
配置SDK后,您将可以访问各种模块及其相应的方法。
sdk.[module].[q or tx or field].[Method](**kwargs)
每个方法将单个参数作为对象(即请求),然后返回对象(即响应)。要查看请求和响应类型,请参阅curium/proto/[模块]以查询和交易。
response = await sdk . db . q . Read (
QueryReadRequest (
uuid = uuid ,
key = "myKey" ,
),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)
print ( reponse )*注意:响应是一个uint8array,代表已查询的字节编码值。要获取值的字符串代表,请使用新的TextDecoder()。解码(desp.Value)
response = await sdk . bank . q . Balance (
QueryBalanceRequest (
address = sdk . wallet . address ,
denom = "ubnt" ,
),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)
print ( response )SDK也可以将交易发送到链条。每个模块都有一个TX方法来发送各种交易消息。
await sdk . db . tx . Create (
MsgCreate (
creator = sample_creator ,
uuid = uuid ,
key = "myKey" ,
value = "myValue" . encode ( "utf-8" ),
lease = Lease ( hours = 1 ),
),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)*注意:SDK正在签署和发送事务,因此签名地址必须与交易的创建者匹配。否则,将抛出错误
**注意:请参阅bluzelle.codec.crud.lease_pb2查看租赁接口
将多条消息包裹在一次交易中。
await sdk . db . with_transactions (
[
MsgCreate (
creator = sdk . wallet . address ,
uuid = uuid ,
key = "firstKey" ,
value = "firstValue" . encode ( "utf-8" ),
lease = Lease ( hours = 1 ),
),
MsgCreate (
creator = sdk . wallet . address ,
uuid = uuid ,
key = "secondKey" ,
value = "firstValue" . encode ( "utf-8" ),
lease = Lease ( hours = 1 ),
),
MsgCreate (
creator = sdk . wallet . address ,
uuid = uuid ,
key = "thirdKey" ,
value = "firstValue" . encode ( "utf-8" ),
lease = Lease ( hours = 1 ),
),
],
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
memo = "optionalMemo" ,
)注意:如果任何一条消息中的任何一条函数中的任何一条失败,则将所有消息传递给Transaction,则所有消息都会失败,并且不投入块
在数据库中创建一个键值。
await sdk . db . tx . Create (
MsgCreate (
creator = sample_creator ,
uuid = uuid ,
key = "someKeyB" ,
value = "someValue" . encode ( "utf-8" ),
lease = Lease ( days = 1 ),
),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)返回:msgcreateresponse(空对象)
| msgcreaterequest | 描述 | 类型 |
|---|---|---|
| 创造者 | 签名地址 | str |
| UUID | 数据库标识符 | str |
| 钥匙 | str | |
| 价值 | 字节 | |
| 元数据 | 字节 | |
| 租 | 钥匙值寿命 | 租 * |
*租赁(秒=数字,分钟=数字,小时=数字,天=数字,数字,年=数字)
删除数据库中的键值。
await sdk . db . tx . Delete (
MsgDelete ( creator = sample_creator , uuid = "myUuid" , key = "myKey" ),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)返回:msgdeleteresponse(空对象)
| msgdeleterequest | 描述 | 类型 |
|---|---|---|
| 创造者 | 签名地址 | str |
| UUID | 数据库标识符 | str |
| 钥匙 | 删除的关键 | str |
续签指定的UUID中的所有钥匙值租赁。
response = await sdk . db . tx . DeleteAll ( creator = sample_creator , uuid = "myUuid" )
print ( response )返回:Promise => msgdeleteallresponse(空对象)
| msgdeleteallrequest | 描述 | 类型 |
|---|---|---|
| 创造者 | 签名地址 | str |
| UUID | 数据库标识符 | str |
在指定的UUID中更新一组键值。
await sdk . db . tx . MultiUpdate (
creator = sample_creator ,
uuid = "myUuid" ,
keyValues = [
MsgUpdate (
creator = sample_creator ,
uuid = "uuid" ,
key = "myKey-1" ,
value = "updatedValue-2" . encode ( "utf-8" ),
lease = Lease ( minutes = 1 ),
),
MsgUpdate (
creator = sample_creator ,
uuid = "uuid" ,
key = "myKey-2" ,
value = "updatedValue-2" . encode ( "utf-8" ),
lease = Lease ( minutes = 1 ),
),
],
)返回:msgmultiupdateresponse(空对象)
| msgmultiupdaterequest | 描述 | 类型 |
|---|---|---|
| 创造者 | 签名地址 | 细绳 |
| UUID | 数据库标识符 | 细绳 |
| 关键价值 | KeyValuelease(钥匙:str,价值:字节,租赁:租赁) | KeyValuelease [] |
更新数据库中的键值租赁。
await sdk . db . tx . Rename (
MsgRename (
creator = sample_creator , uuid = "myUuid" , key = "existingKey" , newKey = "renamingKey"
),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)返回:msgrenameresponse(空对象)
| msgrenamerequest | 描述 | 类型 |
|---|---|---|
| 创造者 | 签名地址 | str |
| UUID | 数据库标识符 | str |
| 钥匙 | 现有密钥 | str |
| 纽基 | 用于重命名的新密钥 | str |
更新数据库中的键值租赁。
respons = await sdk . db . tx . RenewLease (
MsgRenewLease (
creator = sample_creator , uuid = "myUuid" , key = "existingKey" , lease = Lease ( hours = 1 )
),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)返回:msgrenewleaseresponse(空对象)
| MSGRENEWLEASEREQUEST | 描述 | 类型 |
|---|---|---|
| 创造者 | 签名地址 | str |
| UUID | 数据库标识符 | str |
| 钥匙 | str | |
| 租 | 钥匙值的新寿命 | 租 * |
*租赁(秒=数字,分钟=数字,小时=数字,天=数字,数字,年=数字)
续签指定的UUID中的所有钥匙值租赁。
await sdk . db . tx . RenewLeasesAll (
MsgRenewLeasesAll (
creator = sample_creator ,
uuid = uuid ,
lease = Lease ( seconds = 10 ),
),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)返回:msgrenewleasesallresponse(空对象)
| msgrenewleasesallrequest | 描述 | 类型 |
|---|---|---|
| 创造者 | 签名地址 | str |
| UUID | 数据库标识符 | str |
| 租 | 所有钥匙价值的新寿命 | 租 * |
*租赁(秒=数字,分钟=数字,小时=数字,天=数字,数字,年=数字)
更新数据库中的键值。
await sdk . db . tx . Update (
MsgUpdate (
creator = sample_creator ,
uuid = uuid ,
key = "myKey" ,
value = "updatedValue" . encode ( "utf-8" ),
lease = Lease ( minutes = 1 ),
),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)返回:msgupdateresponse(空对象)
| MSGUPDATEREQUEST | 描述 | 类型 |
|---|---|---|
| 创造者 | 签名地址 | str |
| UUID | 数据库标识符 | str |
| 钥匙 | str | |
| 价值 | 新价值要更新到 | 字节 |
| 元数据 | 字节 | |
| 租 | 钥匙值寿命 | 租 |
*租赁(秒=数字,分钟=数字,小时=数字,天=数字,数字,年=数字)
在数据库中提高键值:如果不存在键,请创建一个键值,请更新键值,如果键存在
await sdk . db . tx . Upsert (
MsgUpsert (
creator = sample_creator ,
uuid = "myUuid" ,
key = "keyToUpsert" ,
value = "valueToUpsert" . encode ( "utf-8" ),
),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)返回:msgupsertresponse(空对象)
| msgupsertrequest | 描述 | 类型 |
|---|---|---|
| 创造者 | 签名地址 | str |
| UUID | 数据库标识符 | str |
| 钥匙 | str | |
| 价值 | 字节 | |
| 元数据 | 字节 | |
| 租 | 钥匙值寿命 | 租 * |
*租赁(秒=数字,分钟=数字,小时=数字,天=数字,数字,年=数字)
查询指定UUID中的键值总数。
await sdk . db . q . Count (
MsgCount ( uuid = "myUuid" ),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)返回:querycountresponse
| QueryCountrequest | 描述 | 类型 |
|---|---|---|
| UUID | 数据库标识符 | str |
| QueryCountresponse | 描述 | 类型 |
|---|---|---|
| 数数 | UUID中的键值数量 | int |
获取钥匙价值的剩余租赁时间。
response = await sdk . db . q . GetLease (
QueryGetLeaseRequest (
uuid = uuid ,
key = "myKey" ,
),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)返回:QuerygetLeaseresponse
| QuerygetLeaseRequest | 描述 | 类型 |
|---|---|---|
| UUID | 数据库标识符 | str |
| 钥匙 | str |
| QuerygetLeaseresponse | 描述 | 类型 |
|---|---|---|
| 秒 | 剩余的键值租赁时间 | 数字 |
获取钥匙值的剩余时间。
response = await sdk . db . q . GetNShortestLeases (
QueryGetNShortestLeasesRequest (
uuid = uuid ,
num = 5 ,
),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)返回:querygetnshortestleasesponse
| querygetnshortestleasesrequest | 描述 | 类型 |
|---|---|---|
| UUID | 数据库标识符 | str |
| num | 要返回的钥匙扣数量 | int |
| querygetnshortestleasesresponse | 描述 | 类型 |
|---|---|---|
| 钥匙扣 | KeyLease(键=字符串,秒=数字) | 列表(KeyLease) |
检查指定的UUID中是否存在密钥。
await sdk . db . q . Has (
MsgHas (( uuid = "myUuid" ), ( key = "myKey" )),
( timeout = 3000 ),
( metadata = None ),
( credentials = None ),
( wait_for_ready = True ),
( compression = False )
);返回:queryhasresponse
| queryhasrequest | 描述 | 类型 |
|---|---|---|
| UUID | 数据库标识符 | str |
| 钥匙 | str |
| queryhasresponse | 描述 | 类型 |
|---|---|---|
| 有 | 如果关键在uuid中存在,则为是真的;否则为错误 | 布尔 |
阅读指定UUID中的完整键。 ### hhio
await sdk . db . q . Keys (
MsgKeys ( uuid = "myUuid" , pagination = { "start" : "key-a" , "limit" : 50 }),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)返回:querykeysresponse
| querykeysrequest | 描述 | 类型 |
|---|---|---|
| UUID | 数据库标识符 | str |
| 分页(可选) | pagingRequest(startKey =字符串,limit = long) | pagingrequest |
| querykeysresponse | 描述 | 类型 |
|---|---|---|
| 钥匙 | 列表(str) | |
| 分页(可选) | pagingResponse {nextkey:string,total:long} | 打pagingResponse |
阅读指定UUID中的完整键值集。
response = await sdk . db . q . KeyValues (
QueryKeyValuesRequest ( uuid = uuid ),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)返回:queryKeyvaluesResponse
| QueryKeyKeyvaluesRequest | 描述 | 类型 |
|---|---|---|
| UUID | 数据库标识符 | str |
| 分页(可选) | pagingrequest {startKey:string,limit:long} | pagingrequest |
| queryKeyValuesResponse | 描述 | 类型 |
|---|---|---|
| 关键价值 | keyValue {key:string,value:uint8array} | 列表(KeyValue) |
| 分页(可选) | pagingResponse {nextkey:string,total:long} | 打pagingResponse |
通过指定的UUID中的地址读取完整的键。 ### hhio
await sdk . db . q . Keys (
MsgKeys (( uuid = "myUuid" ), ( address = sample_creator )),
( timeout = 3000 ),
( metadata = None ),
( credentials = None ),
( wait_for_ready = True ),
( compression = False )
);返回:querymykeysresponse
| querymykeysrequest | 描述 | 类型 |
|---|---|---|
| UUID | 数据库标识符 | str |
| 地址 | Bluzelle地址 | str |
| 分页(可选) | pagingrequest {startKey:string,limit:long} | pagingrequest |
| querymykeysresponse | 描述 | 类型 |
|---|---|---|
| 钥匙 | 列表(字符串) | |
| 分页(可选) | pagingResponse {nextkey:string,total:long} | 打pagingResponse |
从数据库中读取一个值。
response = await sdk . db . q . Read (
QueryReadRequest (
uuid = uuid ,
key = "myKey" ,
),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)返回:queryReadResponse
| QueryReadRequest | 描述 | 类型 |
|---|---|---|
| UUID | 数据库标识符 | str |
| 钥匙 | str |
| queryReadResponse | 描述 | 类型 |
|---|---|---|
| 价值 | 字节 |
在指定的UUID中搜索键。
response = await sdk . db . q . Search (
QuerySearchRequest (
uuid = uuid ,
searchString = "s" ,
),
timeout = 3000 ,
metadata = None ,
credentials = None ,
wait_for_ready = True ,
compression = False ,
)返回:querySearchResponse
| querysearchRequest | 描述 | 类型 |
|---|---|---|
| UUID | 数据库标识符 | str |
| 搜索串 | 查询以或匹配搜索串开头或匹配的键 | str |
| 分页(可选) | {startKey:字符串,极限:长} | pagingrequest |
| querysearchResponse | 描述 | 类型 |
|---|---|---|
| 关键价值 | keyValue {key:string,value:uint8array} | 列表(KeyValue) |
| 分页(可选) | {NextKey:String,Total:Long} | 打pagingResponse |