Skip to main content

Async Python client for interacting with the KatapultPro API.

Project description

KatapultAPI

katapultAPI is a Python module designed to handle requests made to the Katapult API.

Installation & Setup

pip install katapult-api

Usage

Getting a Job list and Job Details

import logging.config
import asyncio

# Not required but the client itself has logging functionality to help track requests.
logger = logging.getLogger(__name__)
logging.basicConfig(
        level=logging.DEBUG,
        format='[%(levelname)s] %(asctime)s - %(name)s - %(message)s'
    )

from katapult_api.katapult import Katapult
from katapult_api.utils import task_handler

async def main():

    # Sets up the aiohttp session and closes it after finishing.
    async with Katapult(api_key="YOURAPIKEY") as katapult:

        # Returns a Response object that contains attributes such as return status, content, and even a json() method.
        job_lists = await katapult.job_lists()

        # Here we build 20 payloads that will be sent out at the same time.
        job_ids = [{"job_id":key} for key in list(job_lists.json().keys())[:20]]

        # Not required but makes setting up async tasks easy, pass in a job name and a list of dicts that contain
        # expected params.
        results = await task_handler(katapult.job,job_ids)
    return results

if __name__ == '__main__':
    logger.info(f"Getting jobs...")
    jobs = asyncio.run(main())
    logger.info(f"Finished, got {len(jobs)} jobs.")

Creating a Node

import asyncio

# ...possible logging

from katapult_api.katapult import Katapult

async def main():

    async with Katapult(api_key="YOURAPIKEY") as katapult:

        # get job id from job_lists endpoint...
        job_id = "-ABC123"

        # create a node by passing job id, lat/long, and a flat dict of attributes to write to the node
        results = await katapult.create_node(job_id,30.0817,-97.843,{"OID":123,"my_custom_attr":"howdy partner"})

    return results

if __name__ == '__main__':
    results = asyncio.run(main())

KatapultNice Usage

import logging.config
import asyncio

logging.basicConfig(
    level=logging.DEBUG,
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)

logger = logging.getLogger(__name__)

from katapult_api.katapult import Katapult
from katapult_api.katapult_nice import KatapultNice
from katapult_api.utils import task_handler

async def main(api_key: str):
    async with KatapultNice(api_key=api_key) as nice:
        job_lists = await nice.job_lists()
        job_ids = [{"job_id": key} for key in list(job_lists.json().keys())[:20]]
        results = await task_handler(nice.job_nodes, job_ids)
    return results


if __name__ == '__main__':
    api_key = "api_key"
    logger.info(f"Getting jobs...")
    jobs = asyncio.run(main(api_key))
    logger.info(f"Finished, got {len(jobs)} jobs.")

Resources

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

katapult_api-1.2.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

katapult_api-1.2.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file katapult_api-1.2.0.tar.gz.

File metadata

  • Download URL: katapult_api-1.2.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for katapult_api-1.2.0.tar.gz
Algorithm Hash digest
SHA256 5422bbb25d677697e320e4c34af9ba9d61cf0830bb7dd250f24c047412949ac7
MD5 cceabf0fbe8b67d5a7476fa86776460b
BLAKE2b-256 4011dc86fbb901f2761922719e13aa8cb63c847b456f7eff946f4ce1e71527db

See more details on using hashes here.

File details

Details for the file katapult_api-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: katapult_api-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for katapult_api-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 15e17a65d3cd2350accfa055869f732ef5e8070de5100695038023db780c318f
MD5 486ee9f2ff48e38fc6ec992901eff92d
BLAKE2b-256 9f70746132aaea1e6bd8f6173db39159b8eb72c6d0c3d5343b7f12ef8d86a748

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