Git Product home page Git Product logo

divvy-client-python's Introduction

Divvy Python Client

A client for the Divvy rate limit server. Includes support for Twisted, if that's your jam.

  1. Requirements
  2. Usage
  3. Other Features
  4. License and Copyright

Requirements

  • Procedural client: Python version 2.7 or newer.
  • Twisted client: Python version 2.7 (does not support Python 3) and the Twisted package.

Usage

Procedural client example:

from divvy import DivvyClient

client = DivvyClient("localhost", 8321)
resp = client.check_rate_limit(method="GET", path="/pantry/cookies")
if resp.is_allowed:
	print("Request is within the rate limit: {}".format(resp))
else:
	print("Request exceeds the rate limit: {}".format(resp))

Twisted client example:

from divvy.twisted import DivvyClient


def handle_divvy_response(resp):
	if resp.is_allowed:
		print("Request is within the rate limit: {}".format(resp))
	else:
		print("Request exceeds the rate limit: {}".format(resp))

client = DivvyClient("localhost", 8321)
d = client.check_rate_limit(method="GET", path="/pantry/cookies")
d.addCallback(handle_divvy_response)

Building and testing

pip install requirements.txt  # only needed in the build/test phase
find . -name "*.py" | xargs pycodestyle
pylint -E *.py divvy tests
python -m unittest discover tests/

Other Features

Benchmarking

Benchmark the client -- and your Divvy server -- with the included benchmark.py. Run with -h for comprehensive help. You don't need any special Divvy configuration to run the benchmark, but if you want to simulate a real environment, add this stanza to Divvy's config.ini:

[type=benchmark ip=*]
creditLimit = 5
resetSeconds = 60
actorField = ip
comment = 'for benchmark.py, 5 requests per minute, by IP'

License and Copyright

Licensed under the MIT license. See LICENSE.txt for full terms.

Copyright 2018 Foxpass, Inc.

divvy-client-python's People

Contributors

aren avatar danishfoxpass avatar dependabot[bot] avatar kumar35959 avatar olivecoder avatar ryangwu82 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.