Skip to main content

A stealthy HTTP request library with rotating user agents and proxy support

Project description

StealthKit

Overview

StealthKit is a Python module that provides a stealthy session handler for web scraping and automated requests. It mimics real user behavior by rotating user agents, setting referers, handling cookies, managing proxies, and implementing retry logic.

Features

  • User-Agent Rotation: Automatically rotates user agents from Chrome, Edge, and Safari across different OS platforms (Windows, MacOS, Linux).
  • Random Referer Selection: Simulates real browsing behavior by sending requests with randomized referers from search engines.
  • Cookie Handling: Fetches and stores cookies from specified URLs to maintain session persistence.
  • Proxy Support: Allows requests to be routed through a provided proxy.
  • Retry Logic: Retries failed requests up to three times before giving up.
  • RESTful Requests: Supports GET, POST, PUT, and DELETE methods with automatic proxy integration.

Installation

pip install stealthkit

Basic Usage

from stealthkit import StealthSession

# Create a stealth session
sr = StealthSession()

# Fetch cookies from a base URL
sr.fetch_cookies("https://www.example.com")

# Make a GET request
response = sr.get("https://www.example.com/api")

# Print the response JSON if successful
if response:
    print(response.json())
else:
    print("Failed to fetch data")

Advanced Usage

1. Custom Headers

custom_headers = {
    "Referer": "https://www.example.com",
    "Accept": "application/json",
}
sr.set_headers(custom_headers)

2. Using Proxies

proxies = {"http": "http://proxy.example.com:8080", "https": "https://proxy.example.com:8080"}
sr = StealthSession(proxies=proxies)

3. Retries

sr = StealthSession(retries=5)

4. Fetching Data with Custom Headers

sr.fetch_cookies("https://www.example.com")
custom_headers = {"User-Agent": "Custom-UA"}
sr.set_headers(custom_headers)
response = sr.get("https://www.example.com/api")
print(response.text)

5. Handling Different HTTP Methods

sr.post("https://www.example.com/api", json={"key": "value"})
sr.put("https://www.example.com/api", json={"key": "updated_value"})
sr.delete("https://www.example.com/api")

6. Clearing Cookies

sr.clear_cookies()

7. Retry using Tenacity (nightly)

from tenacity import retry

@retry
def get_response(url):
    sr = StealthSession()
    response = sr.get(url)
    return response.json()

get_response("https://www.example.com/api")

License

This project is licensed under the MIT License.

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

stealthkit-1.0.3.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

stealthkit-1.0.3-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file stealthkit-1.0.3.tar.gz.

File metadata

  • Download URL: stealthkit-1.0.3.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for stealthkit-1.0.3.tar.gz
Algorithm Hash digest
SHA256 99aaef0f8fef52fc4a615248b5cf5da29a7c5a00b430c97400232f5db0e334cc
MD5 909d88b9cf65d09ed159257a04d4d6d0
BLAKE2b-256 6da5c3598e04cce1cfc0c881f3563a54ea2a43d87dfc30b0a9e4c57803433a83

See more details on using hashes here.

File details

Details for the file stealthkit-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: stealthkit-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for stealthkit-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4737d0d7716c6b93403cd528c1a5a097b2f92350b12eb2aef7e94ffa38825214
MD5 5ef70d20ac05dcc8568d17a1cb86974b
BLAKE2b-256 542786143a9b7c696b70173c1738c83e7434b78f8c8dfc5a26dbd51aebd4013a

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