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 code indent in readme.md #183

Merged
merged 4 commits into from
Jul 13, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
wrap the codes in an async funtion
aisk committed May 26, 2024
commit 54b2cd9de62347cfa20cc05c75ceef4d281f7cb5
47 changes: 25 additions & 22 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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/)