update python example (#32)

* update python basic example

* reduce test size to support small servers
This commit is contained in:
Neil Movva
2024-03-21 01:45:09 -07:00
committed by GitHub
parent 9604fd30e1
commit fdb7206517
8 changed files with 39 additions and 46 deletions

View File

@@ -58,9 +58,8 @@ jobs:
name: wheels
path: python/dist
# only run docs on target x86_64
- name: Build Python docs
if: matrix.target == 'x86_64'
if: matrix.target == 'x86_64' # avoids redudundant builds; pdoc isn't arch-specific
working-directory: python
shell: bash
# TODO: pdoc is documenting the installed module, not the source folder.

31
examples/python/basic.py Normal file
View File

@@ -0,0 +1,31 @@
import blyss
api_key = "<YOUR API KEY HERE>"
client = blyss.Client(api_key, "https://alpha.api.blyss.dev")
# Create the bucket and fill it with some data
bucket_name = "state-capitals"
bucket = None
if not client.exists(bucket_name):
client.create(bucket_name)
# Connect to your bucket
bucket = client.connect(bucket_name)
# Write some data (keys are strings, values are bytes)
bucket.write(
{
"California": "Sacramento".encode(),
"Ohio": "Columbus".encode(),
"New York": "Albany".encode(),
}
)
# This is a completely *private* query:
# the server *cannot* learn that you looked up "California" or "Texas"!
print("Privately reading the capital of California...")
capitals = bucket.private_read(["California", "Texas"])
# when a requested key is not found, its value is None
capitals = [c.decode() if c else None for c in capitals]
print(f"Got '{capitals}'!")

View File

@@ -1,37 +0,0 @@
import blyss
import logging
import requests
import json
api_key = "<YOUR API KEY HERE>"
client = blyss.Client(api_key)
# Create the bucket and fill it with some data
bucket_name = "state-capitals"
bucket = None
if not client.exists(bucket_name):
client.create(bucket_name)
# Connect to your bucket
bucket = client.connect(bucket_name)
# Write some data to it
bucket.write(
{
"California": "Sacramento",
"Ohio": "Columbus",
"New York": "Albany",
}
)
# This is a completely *private* query:
# the server *cannot* learn that you looked up "California"!
print("Privately reading the capital of California...")
capital = bucket.private_read("California")
print(f"Got '{capital}'!")
# This is a completely *private* intersection operation:
# the server *cannot* learn that the set was ['Wyoming', 'California', 'Ohio']!
set_to_test = ["Wyoming", "California", "Ohio"]
intersection = bucket.private_key_intersect(set_to_test)
print(f"Intersection of {set_to_test} and bucket yielded: {intersection}")

2
python/Cargo.lock generated
View File

@@ -25,7 +25,7 @@ dependencies = [
[[package]]
name = "blyss-client-python"
version = "0.2.1"
version = "0.2.2"
dependencies = [
"pyo3",
"spiral-rs",

View File

@@ -1,6 +1,6 @@
[package]
name = "blyss-client-python"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
rust-version = "1.70.0"
@@ -11,4 +11,4 @@ crate-type = ["cdylib"]
[dependencies]
pyo3 = { version = "0.17.1", features = ["extension-module"] }
spiral-rs = { path = "../lib/spiral-rs" }
spiral-rs = { path = "../lib/spiral-rs" }

View File

@@ -183,7 +183,7 @@ class API:
"""
try:
await _async_get(
self.api_key, self._service_url_for("/" + bucket_name + CHECK_PATH)
self.api_key, self._service_url_for("/" + bucket_name + META_PATH)
)
return True
except ApiException as e:

View File

@@ -1,7 +1,7 @@
from typing import Any, Optional, Union
from . import bucket, api, seed
BLYSS_BUCKET_URL = "https://beta.api.blyss.dev"
BLYSS_BUCKET_URL = "https://alpha.api.blyss.dev"
DEFAULT_BUCKET_PARAMETERS = {
"maxItemSize": 1000,
"keyStoragePolicy": "none",

View File

@@ -46,7 +46,7 @@ async def test_e2e_async(
client = blyss.AsyncClient(api_key, endpoint)
# generate random string for bucket name
bucket_name = generateBucketName()
await client.create(bucket_name, usage_hints={"maxItemSize": 40_000})
await client.create(bucket_name, usage_hints={"maxItemSize": 10_000})
print("Created bucket")
bucket = await client.connect(bucket_name)
print(await bucket.info())
@@ -117,7 +117,7 @@ def test_e2e(endpoint: str, api_key: str, N: int = 4000, itemSize: int = 32):
client = blyss.Client(api_key, endpoint)
# generate random string for bucket name
bucket_name = generateBucketName()
client.create(bucket_name, usage_hints={"maxItemSize": 40_000})
client.create(bucket_name, usage_hints={"maxItemSize": 10_000})
print("Created bucket")
bucket = client.connect(bucket_name)
print(bucket.info())