Skip to main content

tinylimit is a python modules that limits the calling rate of a function

Project description

Tiny Limit

What is TinyLimit?

tinylimit is a python modules that limits and anti-limits the calling rate of a function 与其他的limit库所不同的是,tinylimit在实战中考虑到了这些因素:

  • 提供anti-limit的方法

    为了让client无视被调用函数所做出的limit限制,我们提供将调用结果保存下来,如果达到被调函数已达调用频率上线,client不是直接报错,而是直接返回最近一次的调用缓存,在某些场景下(比如获取某一日的PV),读取缓存数据并不会令程序逻辑紊乱,却避免了client堵塞。这样client可以按自己的需要随意调用受限函数即可,避免client写冗长的容错逻辑

  • 根据上下文施加limit

    大部分的limit库是以函数为单位做limit,实际上很多第三方的API接口的限制单位为token,不同的token不会共享同一个limit额度,所以以函数名为指纹太泛,我们这里取了类实例的上下文、函数名、函数的参数列表三类信息来形成被调对象的指纹,用以应对这类场景

Programming Language

  • python 2.7
  • python 3.7

Install

pip install tinylimit 

Quick Start

use python decorators syntax to wrap the call target

from tinylimit import AntiLimit

@AntiLimit(2,1)
def Add(a, b):
    return a + b

class Foo():
    @AntiLimit(2,1)
    def Bar(self, a, b):
        return a - b

Functions List

  • AntiLimit()

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

tinylimit-0.1.0.tar.gz (3.1 kB view details)

Uploaded Source

File details

Details for the file tinylimit-0.1.0.tar.gz.

File metadata

  • Download URL: tinylimit-0.1.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/2.7.15

File hashes

Hashes for tinylimit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cdb0fe1af12006dffd0a655557d67cfcc9343ae2b2815e710c5c2f7976ad79fa
MD5 ec12f6a45c643ff39481499ad0132fde
BLAKE2b-256 0c1dba311a130ba74983f826f384f1aa564a2087f1bde6a7a3258474ee1d8514

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