Skip to main content

discovery service client

Project description

Build Status Maintainability codecov

discovery-client

discovery-client package sync/async for consul.

Installing

Install and update using pip:

pip install -U discovery-client

Dependencies

Async client only

Usage Example

using standard client

from discovery.client import Consul


dc = Consul('localhost', 8500)
dc.find_service('consul')

Integration with Flask + threading.

import json
import threading

from discovery.client import Consul

from flask import Flask


app = Flask(__name__)
dc = Consul('discovery', 8500)
dc.register('standard-client', 5000)


@app.route('/manage/health')
def health():
    return json.dumps({'status': 'UP'})


@app.route('/manage/info')
def info():
    return json.dumps({'app': 'standard-client'})


@app.before_first_request
def enable_service_registry():
    def probe_discovery_connection():
        dc.consul_is_healthy()
    thread = threading.Thread(target=probe_discovery_connection)
    thread.start()

using asyncio

client using asyncio

import asyncio

from discovery import aioclient


loop = asyncio.get_event_loop()
dc = aioclient.Consul('localhost', 8500, loop)

search_one_task = loop.create_task(dc.find_service('consul'))
search_all_task = loop.create_task(dc.find_services('consul'))

loop.run_until_complete(search_one_task)
loop.run_until_complete(search_all_task)

using aiohttp

server using aiohttp + asyncio

import asyncio

from aiohttp import web

from discovery.aioclient import Consul


async def service_discovery(app):
    app.loop.create_task(dc.register('aio-client', 5000))
    asyncio.sleep(15)
    app.loop.create_task(dc.consul_is_healthy())


async def handle_info(request):
    return web.json_response({'app': 'aio-client'})


async def handle_status(request):
    return web.json_response({'status': 'UP'})


app = web.Application()
dc = Consul('discovery', 8500, app.loop)

app.on_startup.append(service_discovery)
app.add_routes([web.get('/manage/health', handle_status),
                web.get('/manage/info', handle_info)])
web.run_app(app, host='0.0.0.0', port=5000)

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discovery-client-0.2.2.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

discovery_client-0.2.2-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file discovery-client-0.2.2.tar.gz.

File metadata

  • Download URL: discovery-client-0.2.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.7.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.5

File hashes

Hashes for discovery-client-0.2.2.tar.gz
Algorithm Hash digest
SHA256 bb9ef06022a929db19776ae37de24f2b7e3d8577c2c07dbeed7c6e36c98785d1
MD5 4ff021edf0701095fbd2ad7157512c46
BLAKE2b-256 3ae81ca276a5e8bf6400a68582d83133a8a983bb6b2f234061bb59a5d1c2b23c

See more details on using hashes here.

File details

Details for the file discovery_client-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: discovery_client-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.7.3 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.5

File hashes

Hashes for discovery_client-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8c95119a826541f407035914370c150bfcd9cc589232348acc163ea185ac360d
MD5 047d58cf873265e666e02cfec9caf864
BLAKE2b-256 d501e81ed837425c41b82ec17ef8272a9ad7c9edd866985063e5506161b30234

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page