From 2bac1da4fdd9069f54570457c9e57c9f2cce59fd Mon Sep 17 00:00:00 2001 From: AN Long Date: Sat, 25 May 2024 11:43:46 +0800 Subject: [PATCH 1/4] Fix code indent in readme.md --- readme.md | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/readme.md b/readme.md index 0a9f023..634ad1e 100644 --- a/readme.md +++ b/readme.md @@ -21,8 +21,8 @@ from aiodynamo.credentials import Credentials from aiodynamo.http.httpx import HTTPX from httpx import AsyncClient - async with AsyncClient() as h: - client = Client(HTTPX(h), Credentials.auto(), "us-east-1") +async with AsyncClient() as h: + client = Client(HTTPX(h), Credentials.auto(), "us-east-1") ``` ### With aiohttp @@ -38,31 +38,31 @@ from aiodynamo.credentials import Credentials from aiodynamo.http.aiohttp import AIOHTTP from aiohttp import ClientSession - async with ClientSession() as session: - client = Client(AIOHTTP(session), Credentials.auto(), "us-east-1") +async with ClientSession() as session: + client = Client(AIOHTTP(session), Credentials.auto(), "us-east-1") ``` ### API use ```py - table = client.table("my-table") - - # Create table if it doesn't exist - if not await table.exists(): - await table.create( - Throughput(read=10, write=10), - KeySchema(hash_key=KeySpec("key", KeyType.string)), - ) - - # Create or override an item - await table.put_item({"key": "my-item", "value": 1}) - # Get an item - item = await table.get_item({"key": "my-item"}) - print(item) - # Update an item, if it exists. - await table.update_item( - {"key": "my-item"}, F("value").add(1), condition=F("key").exists() - ) +table = client.table("my-table") + +# Create table if it doesn't exist +if not await table.exists(): + await table.create( + Throughput(read=10, write=10), + KeySchema(hash_key=KeySpec("key", KeyType.string)), + ) + +# Create or override an item +await table.put_item({"key": "my-item", "value": 1}) +# Get an item +item = await table.get_item({"key": "my-item"}) +print(item) +# Update an item, if it exists. +await table.update_item( + {"key": "my-item"}, F("value").add(1), condition=F("key").exists() +) ``` ## Why aiodynamo From 54b2cd9de62347cfa20cc05c75ceef4d281f7cb5 Mon Sep 17 00:00:00 2001 From: AN Long Date: Sun, 26 May 2024 19:51:25 +0800 Subject: [PATCH 2/4] wrap the codes in an async funtion --- readme.md | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/readme.md b/readme.md index 634ad1e..5029048 100644 --- a/readme.md +++ b/readme.md @@ -21,8 +21,9 @@ from aiodynamo.credentials import Credentials from aiodynamo.http.httpx import HTTPX from httpx import AsyncClient -async with AsyncClient() as h: - client = Client(HTTPX(h), Credentials.auto(), "us-east-1") +async def main(): + async with AsyncClient() as h: + client = Client(HTTPX(h), Credentials.auto(), "us-east-1") ``` ### With aiohttp @@ -38,31 +39,33 @@ from aiodynamo.credentials import Credentials from aiodynamo.http.aiohttp import AIOHTTP from aiohttp import ClientSession -async with ClientSession() as session: - client = Client(AIOHTTP(session), Credentials.auto(), "us-east-1") +async def main(): + async with ClientSession() as session: + client = Client(AIOHTTP(session), Credentials.auto(), "us-east-1") ``` ### API use ```py -table = client.table("my-table") - -# Create table if it doesn't exist -if not await table.exists(): - await table.create( - Throughput(read=10, write=10), - KeySchema(hash_key=KeySpec("key", KeyType.string)), +async def main(): + table = client.table("my-table") + + # Create table if it doesn't exist + if not await table.exists(): + await table.create( + Throughput(read=10, write=10), + KeySchema(hash_key=KeySpec("key", KeyType.string)), + ) + + # Create or override an item + await table.put_item({"key": "my-item", "value": 1}) + # Get an item + item = await table.get_item({"key": "my-item"}) + print(item) + # Update an item, if it exists. + await table.update_item( + {"key": "my-item"}, F("value").add(1), condition=F("key").exists() ) - -# Create or override an item -await table.put_item({"key": "my-item", "value": 1}) -# Get an item -item = await table.get_item({"key": "my-item"}) -print(item) -# Update an item, if it exists. -await table.update_item( - {"key": "my-item"}, F("value").add(1), condition=F("key").exists() -) ``` ## Why aiodynamo @@ -73,4 +76,4 @@ await table.update_item( * **Legible source code**. botocore and derived libraries generate their interface at runtime, so it cannot be inspected and isn't typed. aiodynamo is hand written code you can read, inspect and understand. * **Pluggable HTTP client**. If you're already using an asynchronous HTTP client in your project, you can use it with aiodynamo and don't need to add extra dependencies or run into dependency resolution issues. -[Complete documentation is here](https://aiodynamo.readthedocs.io/) +[Complete documentation is here](https://aiodynamo.readthedocs.io/) From a86a1a7242b3092364d4caeb718cab0579d46990 Mon Sep 17 00:00:00 2001 From: AN Long Date: Tue, 28 May 2024 12:23:45 +0800 Subject: [PATCH 3/4] Add client in function parameter in example --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 5029048..116ebda 100644 --- a/readme.md +++ b/readme.md @@ -47,7 +47,7 @@ async def main(): ### API use ```py -async def main(): +async def main(client: Client): table = client.table("my-table") # Create table if it doesn't exist From a0de93e8b75976dfb429fa27ab2b5a309bfb30dd Mon Sep 17 00:00:00 2001 From: Jonas Obrist Date: Sat, 13 Jul 2024 10:06:49 +0900 Subject: [PATCH 4/4] add more imports to readme to explain where things are coming from --- readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.md b/readme.md index 116ebda..7ac7eb4 100644 --- a/readme.md +++ b/readme.md @@ -47,6 +47,10 @@ async def main(): ### API use ```py +from aiodynamo.client import Client +from aiodynamo.expressions import F +from aiodynamo.models import Throughput, KeySchema, KeySpec, KeyType + async def main(client: Client): table = client.table("my-table")