Skip to main content

Encapsulates a framework for requests to request json corresponding package api, while saving the results locally

Project description

SimpleRequestsFramework

Description

This is a simple will be used to request requests wrapped up response package is json at the same time the content will be stored locally api package . Support for GET and POST requests , while supporting multiple proxy protocols , you can preset the Header and other related information .

Installation

pip install simple-requests-framework

Usage

from SimpleRequestFramework import SimpleRequestFramework

custom_headers = {
    "User-Agent": "CustomUserAgent/1.0",
    "Authorization": "Bearer YOUR_TOKEN"
}
# new a framework instance, and set the save directory, use proxy, proxy type, proxy address, and custom headers
framework = SimpleRequestFramework(
    save_directory="output_files",
    use_proxy=True,
    proxy_type="http",
    proxy_address="http://127.0.0.1:8080",
    headers=custom_headers
)

# GET request example
get_url = "https://api.ip.sb/ip"
params = {
    "param1": "value1",
    "param2": "value2"
}
framework.fetch_and_save(get_url, "output_get.json", method="GET", params=params)

# POST request example
post_url = "https://httpbin.org/post"
data = {
    "data1": "value1",
    "data2": "value2"
}
framework.fetch_and_save(post_url, "output_post.json", method="POST", data=data)

Also supports configuration of framework instances as json files

create a json file named config.json

{
    "save_directory": "output_files",
    "use_proxy": true,
    "proxy_type": "http",
    "proxy_address": "http://127.0.0.1:8080",
    "headers": {
      "User-Agent": "CustomUserAgent/1.0",
      "Authorization": "Bearer YOUR_TOKEN"
    }
}
from SimpleRequestFramework import SimpleRequestFramework

framework = SimpleRequestFramework(config_json="config.json")

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

simple-request-framework-0.0.2.tar.gz (3.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page