Skip to content

Commit

Permalink
update python example (#32)
Browse files Browse the repository at this point in the history
* update python basic example

* reduce test size to support small servers
  • Loading branch information
neilmovva authored Mar 21, 2024
1 parent 9604fd3 commit fdb7206
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 46 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 31 additions & 0 deletions examples/python/basic.py
Original file line number Diff line number Diff line change
@@ -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}'!")
37 changes: 0 additions & 37 deletions examples/python/main.py

This file was deleted.

2 changes: 1 addition & 1 deletion python/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "blyss-client-python"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
rust-version = "1.70.0"

Expand All @@ -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" }
2 changes: 1 addition & 1 deletion python/blyss/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async def exists(self, bucket_name: str) -> bool:
"""
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:
Expand Down
2 changes: 1 addition & 1 deletion python/blyss/bucket_service.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions python/tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit fdb7206

Please sign in to comment.