rbw / aiosnow

Asynchronous ServiceNow Library
MIT License
73 stars 12 forks source link

Add asyncio.run() wrapper #105

Closed rbw closed 3 years ago

rbw commented 3 years ago

Add a simple asyncio.run() wrapper that can be used as an alternative to asyncio.run; a simple addition that would result in less code and a more native feel.

Start with a simple wrapper:

def go(func, *args, **kwargs):
    asyncio.run(func())

Usage:

import aiosnow
from aiosnow.models.table.declared import IncidentModel as Incident

ADDRESS = "instance.service-now.com"
CREDENTIALS = "user", "pw"

async def my_func():
    client = aiosnow.Client(ADDRESS, basic_auth=CREDENTIALS)

    async with Incident(client, table_name="incident") as inc:
        for response in await inc.get(limit=5):
            print(response["number"])

aiosnow.go(my_func)