Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: exemple_fastapi didn't use aleph-sdk-python #310

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions examples/example_fastapi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
import aiohttp

logger.debug("import aleph_client")
from aleph_client.asynchronous import create_post, get_messages
from aleph_client.chains.remote import RemoteAccount
from aleph_client.types import StorageEnum
from aleph_client.vm.app import AlephApp
from aleph_client.vm.cache import VmCache
from aleph.sdk.client import AlephClient, AuthenticatedAlephClient
from aleph.sdk.chains.remote import RemoteAccount
from aleph.sdk.types import StorageEnum
from aleph.sdk.vm.app import AlephApp
from aleph.sdk.vm.cache import VmCache

logger.debug("import fastapi")
from fastapi import FastAPI
Expand Down Expand Up @@ -68,9 +68,10 @@ async def environ() -> Dict[str, str]:
@app.get("/messages")
async def read_aleph_messages():
"""Read data from Aleph using the Aleph Client library."""
data = await get_messages(
hashes=["f246f873c3e0f637a15c566e7a465d2ecbb83eaa024d54ccb8fb566b549a929e"]
)
async with AlephClient() as client:
data = await client.get_messages(
hashes=["f246f873c3e0f637a15c566e7a465d2ecbb83eaa024d54ccb8fb566b549a929e"]
)
return {"Messages": data}


Expand Down Expand Up @@ -153,15 +154,17 @@ async def post_a_message():
"answer": 42,
"something": "interesting",
}
response = await create_post(
async with AuthenticatedAlephClient(
account=account,
post_content=content,
post_type="test",
ref=None,
channel="TEST",
inline=True,
storage_engine=StorageEnum.storage,
)
) as client:
response = await client.create_post(
post_content=content,
post_type="test",
ref=None,
channel="TEST",
inline=True,
storage_engine=StorageEnum.storage,
)
return {
"response": response,
}
Expand Down