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.1.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.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ratehttp-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 85652bf6fc50dcac9cbc013a2e2ee247a656de4676285281514f0edc1b8e2cb9
MD5 83aad905260e909fae16c59e41a08c20
BLAKE2b-256 ae94b3b377e3a697acc9d9a13e9bf51ca5aac185f326f95997939bfd65d69b8a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ratehttp-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 214743b6528aba8c64fdfe3e4142046b2dd1e645d6367c5ce34812779856f892
MD5 23f9f408ab9ebf962e72dd896c9a9f1f
BLAKE2b-256 bfc6112eed61b30218b726a8afbd2abb1123172c65ef37bc9ae1708b23936150

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