http

from instahashtag.http import Base, Requests, Aiohttp

Low-level HTTP calls to DisplayPurposes with json returns. Allows customization with “plug-and-play” support for any other Python HTTP request library. Comes out of the box with support for both the requests and aiohttp packages.

Note

The classes documented here are not intended to be used for querying the API- they are here to allow customization support for anyone looking to use their own HTTP request library to send requests to the API.

If you are looking for retrieving back the raw json objects without carying much about implementation, check out the documentations for the api module.


class endpoints[source]

API endpoints.

class endpoints:
    tag = "https://apidisplaypurposes.com/tag/{}"
    graph = "https://apidisplaypurposes.com/graph/{}"
    maps = "https://apidisplaypurposes.com/local/?bbox={},{},{},{}&zoom={}"
class Base(endpoint: str, headers: dict)[source]

Base class that properly processes and calls the API.

Allows one to “plug-and-play” with other request libraries with ease. If one wants to, they may inherit from this class and overwrite the abstract call() method.

Example

While the module httpx is not supported out of the box, one may inherit from the Base class and utilize it.

from instahashtag.http import Base
import httpx

class httpx_io(Base):
    def call(self):
        req = httpx.get(self.endpoint, headers=self.headers)
        resp = req.text

        # Note that self.process is just a simple wrapper for 'json.loads'.
        # One has the option to also overwrite this to catch any extra error(s),
        # or run processes on the data.
        return self.process(resp)

class httpx_aio(Base):
    async def call(self):
        async with httpx.AsyncClient() as client:
            req = await client.get(self.endpoint, headers=self.headers)

        resp = req.text
        return self.process(resp)

def io():
    tag = httpx_io.tag(hashtag="instagram")
    graph = httpx_io.graph(hashtag="instagram")
    maps = httpx_io.maps(
        x1=-80.48712034709753,
        y1=25.750749758162012,
        x2=-79.82794065959753,
        y2=25.854604964203453,
        zoom=12,
    )

def aio():
    tag = await httpx_io.tag(hashtag="instagram")
    graph = await httpx_io.graph(hashtag="instagram")
    maps = await httpx_io.maps(
        x1=-80.48712034709753,
        y1=25.750749758162012,
        x2=-79.82794065959753,
        y2=25.854604964203453,
        zoom=12,
    )
abstract call() → NotImplemented[source]

Abstract method that needs to be written to query the API endpoint.

static process(resp: str) → dict[source]

Processes the reply returned back by tag, graph, and maps.

The current implementation of this function is a simple json.loads(resp), returning back a Python dictionary object. However, one may chose to overwrite this function to process the data in some more meaningful way.

classmethod tag(hashtag: str) → Any[source]

Sends an API request to the tag endpoint.

classmethod graph(hashtag: str) → Any[source]

Sends an API request to the graph endpoint.

classmethod maps(x1: float, y1: float, x2: float, y2: float, zoom: int) → Any[source]

Sends an API request to the maps endpoint.


The classes below are the out-of-the-box implementations used by the higher layers.

class Requests(endpoint: str, headers: dict)[source]

Class that utilitizes the request module to make API request.

class Aiohttp(endpoint: str, headers: dict)[source]

Class that utilitizes the aiohttp module to make API request.