ApiAsyncClient

Async client for ApiDaemon-service


License
MIT
Install
pip install ApiAsyncClient==1.1

Documentation

ApiDaemon is a service for merging any external API. Now project in very-very unstable state.

Project contain three part: server (AsyncIO), asynchronous-client and synchronous-client. I think later it's must be three different projects, because async-client cannot work with python 2 and package cannot install by requirements (asyncio)

Documentation: http://apidaemon.readthedocs.org/en/latest/

Bash-usage

pip install ApiDaemon
apidaemon --genconfig > config.yml

Than edit config.yml as you want:

host: 127.0.0.1
port: 2007
notificator:
    __class__ !!python/name:ApiDaemon.EmailNotificator
    __enabled__: true
    host: smtp.gmail.com
    port: 587
    use_ssl: true
    login: null
    password: null
    receiver: null
    sender_name: ApiDaemon
plugins:
    vk:
        __class__: !!python/name:ApiDaemon.VkPlugin
        __enabled__: true
        app_id: null
        user_login: null
        user_password: null
        access_token: null
    lastfm:
        __class__: !!python/name:ApiDaemon.LastfmPlugin
        __enabled__: true
        key: null
    bar:
        __class__: !!python/name:ApiDaemon.MyBar
        __enabled__: true
        __use_notify__: true
        bar_name: 'Fixprice bar'

And just run

apidaemon -c config.yml

Python-usage

from ApiDaemon import ApiServer

config_path = './config.yml'

if __name__ == '__main__':
    server = ApiServer(config=config_path)

    try:
        server.start()
    except KeyboardInterrupt:
        pass
    finally:
        server.stop()

Client-side

Async client

import asyncio
from ApiDaemon import ApiClient

@asyncio.coroutine
def main(loop=None):
    async_api = ApiClient(host='127.0.0.1', port=2007, loop=loop)

    response = yield from async_api.lastfm.artist.getinfo(artist='Metallica')
    print(response)

    response = yield from async_api.vk.users.get(user_id=1)
    print(response)

loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
loop.close()

Synchronous client

from ApiDaemon import ApiSyncClient

sync_api = ApiSyncClient(host='127.0.0.1', port=2007)

response = sync_api.lastfm.artist.getinfo(artist='Metallica')
print(response)

response = sync_api.vk.audio.get(count=2)
print(response)