Skip to main content

octopus-api

octopus_icon

About

Octopus-api is a python library for performing client-based optimized connections requests and limit rates set by the endpoint contract.

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

Installation

pip install octopus-api

PyPi

https://pypi.org/project/octopus-api/

Get started

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

client = OctopusApi(rate=30, resolution="minute", retries=10)
client = OctopusApi(rate=5, resolution="sec", retries=3)
client = OctopusApi(connections=100, retries=5)

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: TentacleSession, 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 Octopus TentacleSession uses aiohttp under the hood, the resulting way to write POST, GET, PUT and PATCH for aiohttp will be the same for octopus. The only difference is the added functionality of retries and optional rate limit.

Finally, you finish everything up with the execute call for the octopus 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 octopus_api import TentacleSession, OctopusApi
from typing import Dict, List

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


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

Optimize the request based on rate limit constraints:

from octopus_api import TentacleSession, OctopusApi
from typing import Dict, List

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

    client = OctopusApi(rate=30, resolution="minute")
    result: List = client.execute(requests_list=[{
        "url": "http://api.coingecko.com/api/v3/coins/ethereum?tickers=false&localization=false&market_data=false",
        "params": {}}] * 100, func=get_ethereum_id)
    print(result)

Optimize the request based on rate limit and connections limit:

from octopus_api import TentacleSession, OctopusApi
from typing import Dict, List

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

    client = OctopusApi(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=get_ethereum)
    print(result)

Metadata

Release files for octopus-api 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for octopus-api 2.1.0
File Size Uploaded Provenance Actions
octopus-api-2.1.0.tar.gz 16.6 kB Without provenance Details for octopus-api-2.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for octopus-api 2.1.0
File Interpreter ABI Platform Actions
octopus_api-2.1.0-py3-none-any.whl Python 3 none any Details for octopus_api-2.1.0-py3-none-any.whl

Total release size: 33.2 kB

Release files / octopus-api-2.1.0.tar.gz

Download URL octopus-api-2.1.0.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
db75db1ab6396d3c812ad616624dc9f0cf6584fb820e2f025b59ee2a9b4515d3
BLAKE2b-256 checksum
How to use checksums
90dd169e492417bc92187d4ec52a343dc14029a3793a7c9b15eb2161cd72c4d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.7 Darwin/22.2.0

Release files / octopus_api-2.1.0-py3-none-any.whl

Download URL octopus_api-2.1.0-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1cc3bace1c711ded2ce124dc586ddf87c807122c950a89e682b75880457c8f2f
BLAKE2b-256 checksum
How to use checksums
11d85eab718d80224f41e578cbff4124f6e46bfdf8b99b2b81bd6e881eb4980b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.7 Darwin/22.2.0

Security for octopus-api 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page