Skip to content
Closed
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
15 changes: 13 additions & 2 deletions examples/example_fastapi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@

http_app = FastAPI()
app = AlephApp(http_app=http_app)
cache = VmCache()
cache = VmCache(
session=aiohttp.ClientSession(
connector=aiohttp.UnixConnector(path=os.environ["ALEPH_API_UNIX_SOCKET"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user of the SDK should not have to worry about that, the same code should work without a change on the developer's system and inside a microvm.

)
)


ALEPH_API_SERVER = "https://official.aleph.cloud"


@app.get("/")
Expand Down Expand Up @@ -68,7 +75,9 @@ async def environ() -> Dict[str, str]:
@app.get("/messages")
async def read_aleph_messages():
"""Read data from Aleph using the Aleph Client library."""
async with AlephClient() as client:
async with AlephClient(
api_server=ALEPH_API_SERVER, api_unix_socket=os.environ["ALEPH_API_UNIX_SOCKET"]
) as client:
data = await client.get_messages(
hashes=["f246f873c3e0f637a15c566e7a465d2ecbb83eaa024d54ccb8fb566b549a929e"]
)
Expand Down Expand Up @@ -155,6 +164,8 @@ async def post_a_message():
"something": "interesting",
}
async with AuthenticatedAlephClient(
api_server=ALEPH_API_SERVER,
api_unix_socket=os.environ["ALEPH_API_UNIX_SOCKET"],
account=account,
) as client:
response = await client.create_post(
Expand Down