Skip to main content

ratehttp is fork from octopus-api based on aiohttp, and ratehttp provides ssl-verify setting

Project description

About

ratehttp is fork from octopus-api based on aiohttp, but ratehttp provides ssl-verify setting

ratehttp is simple; it combines the asyncio and aiohttp and octopus-api library's functionality and makes sure the requests follows the constraints set by the contract.

Installation

pip install ratehttp

PyPi

https://pypi.org/project/ratehttp/

Get started

To start RateHttp, you first initiate the client, setting your constraints.

client = RateHttp(rate=100, connections=10, retries=5, sll=False)
client = RateHttp(connections=10, retries=3, sll=True)

After that, you will specify what you want to perform on the endpoint response. This is done within a user-defined function.

async def patch_data(session: RateSession, request: Dict):
    async with session.patch(url=request["url"], data=requests["data"], params=request["params"]) as response:
        body = await response.json()
        return body["id"]

As RateHttp RateSession uses aiohttp under the hood, the resulting way to write POST, GET, PUT and PATCH for aiohttp will be the same for RateHttp. The only difference is the added functionality of retries and optional rate limit.

Finally, you finish everything up with the execute call for the RateHttp client, where you provide the list of requests dicts and the user function. The execute call will then return a list of the return values defined in user function. As the requests list is a bounded stream we return the result in order.

result: List = client.execute(requests_list=[
    {
        "url": "http://localhost:3000",
        "data": {"id": "a", "first_name": "filip"},
        "params": {"id": "a"}
    },
    {
        "url": "http://localhost:3000",
        "data": {"id": "b", "first_name": "morris"},
        "params": {"id": "b"} 
    }
    ] , func=patch_data)

Examples

Optimize the request based on max connections constraints:

from ratehttp import RateSession, RateHttp
from typing import Dict, List

if __name__ == '__main__':
    async def fetch_data(session: RateSession, request: Dict):
        async with session.get(url=request["url"], params=request["params"]) as response:
            body = await response.text()
            return body


    client = RateHttp(connections=100)
    result: List = client.execute(requests_list=[{
        "url": "http://google.com",
        "params": {}}] * 100, func=fetch_data)
    print(result)

Optimize the request based on rate limit and connections limit:

from ratehttp import RateSession, RateHttp
from typing import Dict, List

if __name__ == '__main__':
    async def fetch_data(session: RateSession, request: Dict):
        async with session.get(url=request["url"], params=request["params"]) as response:
            body = await response.json()
            return body

    client = RateHttp(rate=50, resolution="sec", connections=6)
    result: List = client.execute(requests_list=[{
        "url": "https://api.pro.coinbase.com/products/ETH-EUR/candles?granularity=900&start=2021-12-04T00:00:00Z&end=2021-12-04T00:00:00Z",
        "params": {}}] * 1000, func=fetch_data)
    print(result)

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

ratehttp-0.1.3.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.

ratehttp-0.1.3-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file ratehttp-0.1.3.tar.gz.

File metadata

  • Download URL: ratehttp-0.1.3.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for ratehttp-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c49fd5a5f2a2b32b34748aefc6c8b58afaa197d41c2afec1dfc4ee47edd88074
MD5 56b344ca5f430e85cc8f6cb466a255dc
BLAKE2b-256 bff118e50ef88d98c56e72f7faa536d007bff4452644dae62f161582a48c625f

See more details on using hashes here.

File details

Details for the file ratehttp-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: ratehttp-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for ratehttp-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 96c503f989ac414acaa28a81690aefb6f70c42ea91adfef1f81cae9841a3844c
MD5 6aa1645b7a8240735331b2fd739fa575
BLAKE2b-256 c757eddad6251877eb3da78d681fed0a7bead06724e5b8b533d7669533bbd9a6

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