### Installing StealthKit Python Library Source: https://github.com/theonlyanil/stealthkit/blob/main/README.md Provides the command-line instruction to install the `stealthkit` package using the Python package installer, `pip`. This is the required first step before using the library. ```sh pip install stealthkit ``` -------------------------------- ### Basic Usage with StealthSession in Python Source: https://github.com/theonlyanil/stealthkit/blob/main/README.md Shows how to initialize a `StealthSession`, fetch initial cookies from a base URL, and perform a simple GET request to an API endpoint. It includes basic error handling and demonstrates accessing the JSON response body. Requires the `stealthkit` library installed. ```python 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") ``` -------------------------------- ### Integrating Tenacity Retry with StealthSession Python Source: https://github.com/theonlyanil/stealthkit/blob/main/README.md Illustrates how to wrap a function that uses `StealthSession` with the `@retry` decorator from the `tenacity` library for external retry management. This requires both `stealthkit` and `tenacity` to be installed. The example makes a GET request within the retried function. ```python 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") ``` -------------------------------- ### Performing Various HTTP Methods with StealthSession Python Source: https://github.com/theonlyanil/stealthkit/blob/main/README.md Provides examples of how to use the `StealthSession` object to make POST, PUT, and DELETE requests to an API endpoint. It demonstrates sending JSON data with POST and PUT requests. Requires an initialized `StealthSession` object. ```python 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") ``` -------------------------------- ### Fetching Data with Cookies and Custom Headers Python Source: https://github.com/theonlyanil/stealthkit/blob/main/README.md Illustrates a workflow where cookies are fetched from a base URL, custom headers (specifically a User-Agent) are set on the session, and then a GET request is made. It demonstrates accessing the raw text content of the response. Requires an initialized `StealthSession`. ```python 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) ``` -------------------------------- ### Initializing StealthSession with Proxies in Python Source: https://github.com/theonlyanil/stealthkit/blob/main/README.md Demonstrates how to pass a dictionary of proxy configurations when creating a `StealthSession` object. This configures the session to route both HTTP and HTTPS requests through the specified proxy servers. Requires proxy server details. ```python proxies = {"http": "http://proxy.example.com:8080", "https": "https://proxy.example.com:8080"} sr = StealthSession(proxies=proxies) ``` -------------------------------- ### Setting Custom Headers in StealthSession Python Source: https://github.com/theonlyanil/stealthkit/blob/main/README.md Illustrates how to define a dictionary of custom HTTP headers and apply them to the `StealthSession` instance using the `set_headers` method. These headers will be included in subsequent requests made by this session. Requires an initialized `StealthSession` object. ```python custom_headers = { "Referer": "https://www.example.com", "Accept": "application/json", } sr.set_headers(custom_headers) ``` -------------------------------- ### Configuring Retries for StealthSession in Python Source: https://github.com/theonlyanil/stealthkit/blob/main/README.md Shows how to specify the maximum number of retries for failed requests by providing the `retries` argument during the initialization of the `StealthSession`. The default is 3 retries. ```python sr = StealthSession(retries=5) ``` -------------------------------- ### Clearing Cookies in StealthSession Python Source: https://github.com/theonlyanil/stealthkit/blob/main/README.md Demonstrates calling the `clear_cookies` method on a `StealthSession` instance. This removes all cookies currently stored within that specific session object, allowing for a fresh session state. Requires an initialized `StealthSession` object. ```python sr.clear_cookies() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.