Skip to content

Commit 5f95edb

Browse files
committed
Polishing the docs
1 parent e0141fa commit 5f95edb

7 files changed

+241
-20
lines changed

README.md

+84-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,101 @@
1-
# aiodike - Python asyncio tools for web service resilience
1+
# dike - Python asyncio tools for web service resilience
22

3-
[<img src="https://img.shields.io/pypi/v/aiodike.svg" alt="Release Status">](https://pypi.python.org/pypi/aiodike)
4-
[<img src="https://github.com/chr1st1ank/aiodike/actions/workflows/test.yml/badge.svg?branch=main" alt="CI Status">](https://github.com/chr1st1ank/aiodike/actions)
5-
[![codecov](https://codecov.io/gh/chr1st1ank/aiodike/branch/main/graph/badge.svg?token=4oBkRHXbfa)](https://codecov.io/gh/chr1st1ank/aiodike)
3+
[<img src="https://img.shields.io/pypi/v/dike.svg" alt="Release Status">](https://pypi.python.org/pypi/dike)
4+
[<img src="https://github.com/chr1st1ank/dike/actions/workflows/test.yml/badge.svg?branch=main" alt="CI Status">](https://github.com/chr1st1ank/dike/actions)
5+
[![codecov](https://codecov.io/gh/chr1st1ank/dike/branch/main/graph/badge.svg?token=4oBkRHXbfa)](https://codecov.io/gh/chr1st1ank/dike)
66

77

8-
* Documentation: <https://chr1st1ank.github.io/aiodike/>
8+
* Documentation: <https://chr1st1ank.github.io/dike/>
99
* License: Apache-2.0
1010
* Status: Initial development
1111

1212
## Features
1313

1414
### Concurrency limiting for asynchronous functions
1515
The `@limit_jobs` decorator allows to limit the number of concurrent excecutions of a coroutine
16-
function.
16+
function. This can be useful for limiting queueing times or for limiting the load put
17+
onto backend services.
18+
19+
Example with an external web request using the [httpx](https://github.com/encode/httpx) library:
20+
21+
```python
22+
import asyncio
23+
import httpx
24+
import dike
25+
26+
27+
@dike.limit_jobs(limit=2)
28+
async def web_request():
29+
async with httpx.AsyncClient() as client:
30+
response = await client.get("https://httpstat.us/200?sleep=100")
31+
return response
32+
33+
34+
async def main():
35+
responses = await asyncio.gather(
36+
web_request(), web_request(), web_request(), return_exceptions=True
37+
)
38+
for r in responses:
39+
if isinstance(r, dike.TooManyCalls):
40+
print("too many calls")
41+
else:
42+
print(r)
43+
44+
45+
asyncio.run(main())
46+
```
47+
48+
The output shows that the first two requests succeed. The third one hits the concurrency limit:
49+
```
50+
<Response [200 OK]>
51+
<Response [200 OK]>
52+
too many calls
53+
```
1754

1855
### Mini-batching for asynchronous function calls
1956
The `@batch` decorator groups function calls into batches and only calls the wrapped function
20-
once on the collected input.
57+
with the aggregated input.
58+
59+
This is useful if the function scales well with the size of the input arguments but you're
60+
getting the input data in smaller bits, e.g. as individual HTTP requests.
61+
62+
Example:
63+
64+
```python
65+
import asyncio
66+
import dike
67+
68+
69+
@dike.batch(target_batch_size=3, max_waiting_time=10)
70+
async def f(arg1, arg2):
71+
print(f"arg1: {arg1}")
72+
print(f"arg2: {arg2}")
73+
return [10, 11, 12]
74+
75+
76+
async def main():
77+
result = await asyncio.gather(
78+
f([0], ["a"]),
79+
f([1], ["b"]),
80+
f([2], ["c"]),
81+
)
82+
83+
print(f"Result: {result}")
84+
85+
86+
asyncio.run(main())
87+
```
88+
89+
Output:
90+
```
91+
arg1: [0, 1, 2]
92+
arg2: ['a', 'b', 'c']
93+
Result: [[10], [11], [12]]
94+
```
2195

2296
## Installation
97+
Simply install from pypi. The library is pure Python without any dependencies other than the
98+
standard library.
2399
```
24-
pip install aiodike
100+
pip install dike
25101
```

docs/api.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# API documentation
2+
3+
## Decorators
4+
![mkapi](dike.limit_jobs|short)
5+
![mkapi](dike.batch|short)
6+
7+
## Exceptions
8+
![mkapi](dike.TooManyCalls|short)

docs/authors.md

-3
This file was deleted.

mkdocs.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
site_name: dike
2+
repo_url: https://github.com/chr1st1ank/dike
3+
site_url: https://github.io/chr1st1ank/dike
4+
repo_name: dike
5+
nav:
6+
- Home: index.md
7+
- Installation: installation.md
8+
# - Usage: usage.md
9+
- API documentation: api.md
10+
- History: history.md
11+
- Contributing: contributing.md
12+
theme:
13+
name: readthedocs
14+
language: en
15+
highlightjs: true
16+
markdown_extensions:
17+
- admonition
18+
# - toc:
19+
# baselevel: 1
20+
# permalink: true
21+
- meta
22+
- pymdownx.highlight
23+
- pymdownx.superfences
24+
- pymdownx.snippets
25+
plugins:
26+
- include-markdown
27+
- autorefs
28+
- search:
29+
lang: en
30+
- mkapi:
31+
src_dirs:
32+
- .

poetry.lock

+111-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[tool]
22
[tool.poetry]
3-
name = "aiodike"
3+
name = "dike"
44
version = "0.1.0"
5-
homepage = "https://github.com/chr1st1ank/aiodike"
5+
homepage = "https://github.com/chr1st1ank/dike"
66
description = "Python asyncio tools for web service resilience."
77
authors = ["Christian Krudewig <[email protected]>"]
88
readme = "README.md"
@@ -18,12 +18,13 @@ classifiers = [
1818
'Programming Language :: Python :: 3.9',
1919
]
2020
packages = [
21-
{ include = "aiodike" },
21+
{ include = "dike" },
2222
{ include = "tests", format = "sdist" },
2323
]
2424

2525
[tool.poetry.dependencies]
2626
python = ">=3.7.1,<4.0"
27+
pymdown-extensions = {version = "^8.2", extras = ["docs"]}
2728

2829
[tool.poetry.extras]
2930
test = [
@@ -67,6 +68,7 @@ yamllint = "*"
6768
pylint-junit = "*"
6869
numpy = "^1.21.0"
6970
pytest-parametrized = "^1.3"
71+
httpx = "^0.18.2"
7072

7173
[build-system]
7274
requires = ["poetry-core>=1.0.0"]

0 commit comments

Comments
 (0)