Metadata-Version: 2.4
Name: anon_requests
Version: 1.0.0a1
Summary: Anonymous HTTP requests via rotating proxies and Tor
Author-email: JarbasAI <jarbasai@mailfence.com>
License: Apache-2.0
Project-URL: Homepage, https://github.com/TigreGotico/anon_requests
Project-URL: Repository, https://github.com/TigreGotico/anon_requests
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: requests>=2.11.0
Requires-Dist: PySocks>=1.5.7
Requires-Dist: stem>=1.4.0
Requires-Dist: bs4
Requires-Dist: requests_cache
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Dynamic: license-file

# Anon Requests

anonymous python requests

## Install

```bash
pip install anon_requests
```

## Usage

see [examples folder](./examples) for more use cases

Proxies
```python
from anon_requests import RotatingProxySession
from anon_requests import ProxyType

# validate=True will check if all proxies are functioning (default False)
# validated proxies will be used first
# "bad" proxies will be tried once you run out of good proxies
# everytime it runs out of unused proxies, it will start reusing old ones
# pass ignore_bad=False to not try the "bad" proxies at all (default True)
with RotatingProxySession(proxy_type=ProxyType.SOCKS5, validate=True) \
        as session:
    for i in range(5):
        # every request rotates proxy before being made
        # keeps trying until we get 200 status code
        # will only repeat a proxy once all have been tried
        # this means it can hang for a while here until request succeeds
        response = session.get('https://ipecho.net/plain', timeout=5)
        print(response.text)  # Not your ip address, different every time
```

Tor
```python
from anon_requests import RotatingTorSession

# Choose a proxy port, a control port, and a password.
# Defaults are 9050, 9051, and None respectively.
# If there is already a Tor process listening the specified
# ports, TorSession will use that one.
# Otherwise, it will create a new Tor process,
# and terminate it at the end.
with RotatingTorSession(proxy_port=9050, ctrl_port=9051,
                        password="MYSUPERSAFEPSWD") as session:
    for i in range(5):
        response = session.get('https://ipecho.net/plain')
        print(response.text)  # not your IP address, different every time
```

## Custom transport

Every session accepts a `session_factory` — any callable returning a
`requests.Session` (the default is `requests.Session`). Rotation and proxy/Tor
settings are applied to whatever session the factory returns, so you can layer
a custom transport (for example an anti-bot session that bypasses Cloudflare)
under the rotation.

```python
from anon_requests import RotatingProxySession, ProxyType

# any requests.Session subclass works here
with RotatingProxySession(
        proxy_type=ProxyType.SOCKS5,
        session_factory=lambda: MyAntiBotSession()) as session:
    response = session.get('https://ipecho.net/plain', timeout=5)
```

See [examples/composable_transport.py](./examples/composable_transport.py).

## Proxy Sources

Proxies are scrapped from the following websites

- http://free-proxy.cz
- https://free-proxy-list.net
- https://www.socks-proxy.net
- https://www.sslproxies.org
- https://www.us-proxy.org
- https://hidemy.name
- http://proxydb.net
- https://www.proxynova.com
- https://www.proxyscan.io
- http://pubproxy.com
- https://spys.me
- https://spys.one

## TODO

- import/export proxy list
- suggest more in github issues!
