Skip to main content

Create your own python library for interacting with any website's API.

Project description

api-hijacker

This module was built to easily create python wrappers onto existing APIs.
Using the cloudscraper module most website's endpoints can be accessed without issues.

Installation

PyPI version

You can install this package using pip:

pip install api-hijacker

Use case example:

Project/
├── main.py
└── Service/
    └── api.py

api.py:

import apiCore
from apiCore import request

BASE_URL = "https://api.example.com/users"

# Error-handled function to fetch user data
@request()
def fetch_user(user_id, **kwargs):
    return apiCore.get(f"{BASE_URL}/{user_id}", **kwargs)

# Error-handled function to create a new user
@request(errorHandler=apiCore.HTTPErrorHandler().allow(429))
# in this example status code 429 indicates that captcha authentication is required
# thanks to the .allow() method this statu code will not be retried / excepted
def create_user(data, **kwargs):
    return apiCore.post(BASE_URL, json=data, **kwargs)

# Error-handled function to update user data
@request(retries=10, exponentialBackoff=True)
# more retries and each time wait longer before next retry
def update_user(user_id, data, **kwargs):
    return apiCore.put(f"{BASE_URL}/{user_id}", json=data, **kwargs)

# Error-handled function to delete a user
@request()
def delete_user(user_id, **kwargs):
    return apiCore.delete(f"{BASE_URL}/{user_id}", **kwargs)

main.py:

from Service import api

api.fetch_user(userId)  # returns requests.Response

# proxy example
proxy = {
    "http": "http://http-proxy.example:1234",
    "https": "https://https-proxy.example:1234"
}

api.create_user(user_data, proxy=proxy)  # proxy keyword argument is passed to handle.request()

With cloudscraper this module allows for fast integration with webscraping to easily interact with websites lacking API documentation and/or python libraries.

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

api_hijacker-0.2.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

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

api_hijacker-0.2.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file api_hijacker-0.2.0.tar.gz.

File metadata

  • Download URL: api_hijacker-0.2.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for api_hijacker-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4d76310da02ea0ea88dd922152d9fcd927300c3cabc580f43390a0cb2468edf7
MD5 477d560c6e3cb5f2cbf5a5b4d68f36a9
BLAKE2b-256 6ecb93779ab1f39e07c35041e910479fd7338a59fc27157c7e7952054614f8ef

See more details on using hashes here.

File details

Details for the file api_hijacker-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: api_hijacker-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for api_hijacker-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 db1586290137aae96c9296929c18539373773b3c33c2dbbb0267bd09bb307232
MD5 9c7829987d7ad1522d1f465489abd7f8
BLAKE2b-256 01702bd754cc46b2c252e8b6049621eb13db0f7b565bb88b8e4f39f0cb4e2bb4

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