Skip to main content

ak_requests

Requests package with QOL improvements and anti-bot detection measures

View Demo · Documentation · Report Bug · Request Feature


GitHub commit activity GitHub last commit tests

Table of Contents

1. About the Project

ak_requests is a Python package that provides an interface for automating requests tasks using requests package. It comes with quality of life improvements like retires, custom redirects, spacing out requests and shuffling requests to not trigger anti-bot measures

1.1. Features

  • Bulk requests handling
  • Built-in retries and timeouts
  • Can log processes to file
  • Handles downloads of files/videos
  • Implemented default rate-limiting checks and process
  • Session objects are serialized to be able to save/load sessions from file
  • Can choose to handle exceptions or skip it completely with RAISE_EXCEPTIONS attribute
  • Can support both basic .basic_auth() and OAuth .oauth2_auth() authentications.

2. Getting Started

2.1. Installation

2.1.1. Production

Download the repo and install with flit

pip install flit
flit install --deps production

Alternatively, you can use pip

pip install ak_requests

2.1.2. Development

Install with flit

  flit install --pth-file

3. Usage

from ak_requests import RequestsSession

# Initialize session
session = RequestsSession(log=False, retries=5, log_level='error', timeout=10) 

## Can update session level variables
session.MIN_REQUEST_GAP = 1.5   # seconds, Change min time bet. requests
session.RAISE_ERRORS = False    # raises RequestErrors, else returns None; defaults to True

# Update custom header
session.update_header({'Connection': 'keep-alive'})

# set cookies
session.update_cookies([{'name':'has_recent_activity', 'value':'1'}])

# Get requests
res = session.get('https://reqres.in/api/users?page=2', data={}, proxies = {} ) # Can accept any requests parameters

# Make bulk requests
urls = ['https://reqres.in/api/users?page=2', 'https://reqres.in/api/unknown']
responses = session.bulk_get(urls)

# use beautifulsoup
from ak_requests import soupify
res = session.get('https://reqres.in/api/users?page=2')
soup = soupify(res)

## or 
soup, res = session.soup('https://reqres.in/api/users?page=2')

## Also works for bulk requests
soups, ress = session.bulk_soup(urls)

# Download files
## Check if file is downloadble
session.downloadble('https://www.youtube.com/watch?v=9bZkp7q19f0')  #False

session.downloadble('http://google.com/favicon.ico') #True

session.download(
  url = 'http://google.com/favicon.ico',  #URL to download
  fifopath='C:\\', #Can be folderpath, filename or filepath. If existing folder specified - will extract filename from url contents
  confirm_downloadble = False #Will return `None`, if url not downloadble
)

# Download videos
from pathlib import Path
video_info = session.video(url='https://www.youtube.com/watch?v=BaW_jenozKc', 
              folderpath=Path('.'),
              audio_only=False) #Downloads the video to specified path and returns dict of video info

# Save/Restore session to/from file
## Save the session state to a file
session.save_session('session_state.pkl')

## Later, you can load the session state back
restored_session = RequestsSession.load_session('session_state.pkl')

# Authentication
session.basic_auth(username="johndoe", password="12345678") ## basic auth
session.oauth2_auth(token='x0-xxxxxxxxxxxxxxxxxxxxxxxx')    ## OAuth authentication

4. Roadmap

  • Proxy
  • Asynchronous Requests
  • Response Caching
  • Request Preprocessing and Postprocessing
  • File Upload Support

5. License

See LICENSE for more information.

6. Contact

Arun Kishore - @rpakishore

Project Link: https://github.com/rpakishore/ak_requests

7. Acknowledgements

Metadata

Release files for ak_requests 0.1.1

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

Source distribution (sdist)

Source distribution for ak_requests 0.1.1
File Size Uploaded
ak_requests-0.1.1.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ak_requests 0.1.1
File Interpreter ABI Platform
ak_requests-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 21.0 kB

Release files / ak_requests-0.1.1.tar.gz

Download URL ak_requests-0.1.1.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0bad28ecb2be89f00b393ee25501067b74a3f2dfd6f2ab4d59b75919e05611d7
BLAKE2b-256 checksum
How to use checksums
caf347440b60ecd6f8d103c0ab7b2b8f1f249f85f18484cf378f8a2dd3c94e66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release files / ak_requests-0.1.1-py3-none-any.whl

Download URL ak_requests-0.1.1-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b341598cd342c3ecddc1a054014848b87a6f07533f563f9aa7a3224e1b4ddd8
BLAKE2b-256 checksum
How to use checksums
3c1e979135c1c300b0592f5774a349f6118252cea1e34846d60901aa339cf1fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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