Metadata-Version: 2.0
Name: takumi-client
Version: 0.1.1
Summary: Thrift client pool for Takumi
Home-page: https://github.com/elemepi/takumi-client
Author: Eleme Lab
Author-email: imaralla@icloud.com
License: UNKNOWN
Platform: UNKNOWN
Requires-Dist: takumi-config
Requires-Dist: takumi-thrift
Requires-Dist: thriftpy
Requires-Dist: schema

takumi_client
=============

.. image:: https://travis-ci.org/elemepi/takumi-client.svg?branch=master
    :target: https://travis-ci.org/elemepi/takumi-client


Thrift client pool for Takumi.

Install
-------

.. code:: bash

    $ pip install takumi-client

Usage
-----

This module relies on `takumi-config <https://github.com/elemepi/takumi-config>`_ for settings.

- ``CLIENT_SETTINGS``

  * service_name: required, service name defined in thrift file
  * thrift_file: required, existing thrift file path
  * pool_size: optional, connection pool size, default 30
  * timeout: optional, connection timeout, default 30s
  * check_time: optional, time interval for checking failed connections, default 10s
  * hosts: optional, a list of hosts: [('hostname', port)]
  * hosts_class: optional, alternative class used to load hosts, default ``takumi_client.hosts.ListHosts``
  * extra args: vary for different hosts classes


Example settings:

.. code:: python

    CLIENT_SETTINGS = {
        'demo': {
            'service_name': 'PingService',
            'thrift_file': 'ping.thrift',
            'hosts': [
                ('localhost', 1990),
                ('localhost', 8010),
                ('localhost', 1890)
            ]
        }
    }

To get a pool:

.. code:: python

    from takumi_client import clients

    pool = clients['demo']


To invoke an api:

.. code:: python

    with pool.client_ctx() as c:
        c.ping()


