Metadata-Version: 2.4
Name: t-proxy-toolkit
Version: 0.2.1
Summary: Wrapper around selenium and requests to make it easier to use proxies.
Home-page: https://www.thoughtful.ai/
Author: Thoughtful
Author-email: support@thoughtful.ai
Keywords: t-proxy-toolkit
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: requests<3.0.0,>=2.31.0
Requires-Dist: retry~=0.9.2
Requires-Dist: rpaframework>=29.0.0
Requires-Dist: fake-useragent==2.0.3
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# t-proxy-toolkit #
A wrapper around rpaframework selenium driver to enable proxy usage with Oxylabs. You can also use this tool to start a request session using Oxylabs.

# Installation #

Install using pip:

```pip install t-proxy-toolkit```

# Usage #

## Browser Usage ##

Instead of creating a selenium object directly from rpaframework, use this library's `chrome` or `firefox` methods. You can optionally provide initialization preferences or options for the browser as a dictionary.

By default, the browser will be assigned a custom UserAgent using the fake-useragent package with these settings:

```python
from fake_useragent import UserAgent

user_agent = UserAgent(os="windows", min_percentage=1.3)

# For chrome
user_agent.chrome

# For firefox
user_agent.firefox
```

> **Warning**: Headless mode cannot be used when installing browser extensions

Basic usage example:

```python
from t_proxy import BrowserProxy
from RPA.Browser.Selenium import Selenium

browser_proxy = BrowserProxy()

# Proxy credentials
user = "your_username"
password = "your_password" 
host = "proxy.host.com"
port = "12345"

# Initialize browsers - type hints added for better IDE support
firefox: Selenium = browser_proxy.firefox(user, password, host, port)
chrome: Selenium = browser_proxy.chrome(user, password, host, port)
```

You can create a new user for metrics and usage tracking in the Oxylabs dashboard.

## Browser Configuration ##

### Firefox Preferences ###
You can configure Firefox by passing a preferences dictionary. Reference the following Mozilla documentation for available preferences:

* [firefox.js](https://searchfox.org/mozilla-release/source/browser/app/profile/firefox.js)
* [all.js](https://searchfox.org/mozilla-release/source/modules/libpref/init/all.js)
* [StaticPrefList.yaml](https://searchfox.org/mozilla-release/source/modules/libpref/init/StaticPrefList.yaml)

Example:

```python
prefs = {
    "download.default_directory": "/path/to/downloads",
    "browser.download.folderList": 2
}

firefox: Selenium = browser_proxy.firefox(user, password, host, port, prefs)
```

### Chrome Options ###
For Chrome, you can pass selenium ChromeOptions. Reference these resources for available options:

* [Chromium command line switches](https://peter.sh/experiments/chromium-command-line-switches/)
* [chrome_switches.cc](https://chromium.googlesource.com/chromium/src/+/master/chrome/common/chrome_switches.cc)
* [Source code search](https://source.chromium.org/search?q=file:switches.cc&ss=chromium%2Fchromium%2Fsrc)

Example:

```python
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")

chrome: Selenium = browser_proxy.chrome(user, password, host, port, options)
```

## Requests Usage ##
Use Oxylabs proxy servers with Python requests. The proxy behavior depends on the port:

- Port 8000: Returns a different IP for each request
- Ports 8001-8010: Uses a fixed IP for all requests

IPs can be managed through the Oxylabs dashboard.

Example:

```python
from t_proxy import RequestsProxy
from requests import Session

# Proxy configuration
creds = {
    "login": "your_username",
    "password": "your_password",
    "port": "8000"  # or 8001-8010 for fixed IP
}

requests_proxy = RequestsProxy()
session: Session = requests_proxy.session(creds)

# Make requests
response = session.get("https://api.ipify.org?format=json")
print(response.json())
```
