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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: ratehttp-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 acf67fb5963cb8bdd5fa5863b5e1c9bca6a3f2dcfd15a2dfab64cc37001c02d9
MD5 45ae4f30d10fbb1937c3a60373ec84d3
BLAKE2b-256 345c1a7bf5cb665d917ed8ceeab1890840f383feb087d863f04a646a4fef00ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ratehttp-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2152b7371311830b957b114b7c847e5473ea403c26a576b0db01d7fde5ebe0c0
MD5 3dfad719b2485da6fe3c634365fa93cf
BLAKE2b-256 036db6ea677eddc8d951cd357e9e5d7ce2f028dfc7b6a8ee23787ff54e5e0398

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