Skip to content

Adds support for async/await API calls (no deps)#16

Merged
fguillot merged 2 commits intokanboard:masterfrom
karthanistyr:feature/async_differently
Jul 30, 2019
Merged

Adds support for async/await API calls (no deps)#16
fguillot merged 2 commits intokanboard:masterfrom
karthanistyr:feature/async_differently

Conversation

@karthanistyr
Copy link
Copy Markdown
Contributor

BREAKING:
Drops support for python 2.7 and < 3.5 (it relies on asyncio (so 2.7 is out), and python versions below 3.5 have different behaviours regarding the thread pool, see: https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.run_in_executor).

I am suggesting this change for your consideration.
Backwards compatibility has been preserved by running the synchronous kanboard.client.Kanboard.execute method into an asyncio executor (for now, only the default executor can be used, but the event loop can be customised via Kanboard() ctor)

Basic usage is to use the coroutines mapped by method calls with the _async suffix.
Example: for a given kb object (of type Kanboard)
Synchronous: kb.create_project(name="My project")
Asynchronous: kb.create_project_async(name="My project")

Fixes #14 (replaces PR #15)

**BREAKING**:
Drops support for python 2.7 and < 3.5 (it relies on asyncio (so 2.7 is out), and python versions below 3.5 have different behaviours regarding the thread pool, see: https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.run_in_executor).

I am suggesting this change for your consideration.
Backwards compatibility has been preserved by running the synchronous `kanboard.client.Kanboard.execute` method into an asyncio executor (for now, only the default executor can be used, but the event loop can be customised via Kanboard() ctor)

Basic usage is to use the coroutines mapped by method calls with the _async suffix.
Example: for a given kb object (of type Kanboard)
Synchronous: kb.create_project(name="My project")
Asynchronous: kb.create_project_async(name="My project")

Fixes #14

Signed-off-by: Antoine Mazeas <antoine@karthanis.net>
Signed-off-by: Antoine Mazeas <antoine@karthanis.net>
@karthanistyr
Copy link
Copy Markdown
Contributor Author

There are no added dependencies with this take on the async/await compatibility.
Some real world data:

sample_program.py

import kanboard
import time
import asyncio

kb = kanboard.client.Kanboard("[REDACTED SERVER URL]",
                              "jsonrpc",
                              "[REDACTED API TOKEN]")

# sync
t1 = time.time()
results = [res for res in [kb.get_all_users(),
                           kb.get_all_groups(),
                           kb.get_all_projects()]]
t2 = time.time()
print("Synchronous mode:", t2-t1)

# async
loop = asyncio.get_event_loop()
t3 = time.time()
results = loop.run_until_complete(asyncio.gather(
                            kb.get_all_users_async(),
                            kb.get_all_groups_async(),
                            kb.get_all_projects_async()))
t4 = time.time()
print("Asynchronous mode:", t4-t3)
$ python sample_program.py
Synchronous mode: 3.0287256240844727
Asynchronous mode: 1.368499755859375

@fguillot fguillot merged commit 2f9cac6 into kanboard:master Jul 30, 2019
@fguillot
Copy link
Copy Markdown
Member

LGTM. Thanks!

@karthanistyr karthanistyr deleted the feature/async_differently branch August 1, 2019 18:40
@ghost ghost locked and limited conversation to collaborators Jan 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[feature request]: Implement client with async calls

2 participants