You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's a quick bit of code to get you started! There's also a few [examples in the folder](https://github.com/davidteather/proxyproviders/tree/main/examples).
42
42
43
+
**Note:** If you want to learn how to web scrape websites check my [free and open-source course for learning everything web scraping](https://github.com/davidteather/everything-web-scraping)
44
+
45
+
### Choose a Proxy Provider
46
+
47
+
If you already haven't, choose which proxy provider to use. You can find a [list in the documentation](https://davidteather.github.io/proxyproviders/#proxyproviders-supported-providers). After choosing, look at the documentation around the specific provider you've choosen. Where needed, we've laid out steps to get api keys in the documentation. These steps will vary slightly by provider. For this example I'll be using the [Webshare Provider](https://davidteather.github.io/proxyproviders/#proxyproviders.providers.webshare.Webshare) because it's both easy to setup and they give you 10 free data center proxies to test out.
48
+
49
+
You can create an account on webshare [here](https://www.webshare.io/?referral_code=3x5812idzzzp) (affiliate link), then head into the [API tab](https://dashboard.webshare.io/userapi/keys) on the side and generate a new token. Keep this API token safe and don't post it publically.
50
+
51
+
### Basic Example
52
+
53
+
After you can list out your proxies with
54
+
```py
55
+
from proxyproviders import Webshare
56
+
57
+
proxy_provider = Webshare(api_key="your-api-key")
58
+
59
+
proxies = proxy_provider.list_proxies()
60
+
61
+
print(proxies)
62
+
```
63
+
64
+
Each provider has their own custom options, the `Webshare` class lets you specify url params according to their [api spec](https://apidocs.webshare.io/proxy-list/list#parameters), here's an example which will only return proxies that are based in the US.
For any shared logic across all types of proxy providers, we use the `ProxyConfig` data class to configure them. The full docs for [ProxyConfig are here](https://davidteather.github.io/proxyproviders/#proxyproviders.proxy_provider.ProxyConfig). In this example we will configure it to use a shorter `refresh_interval` than default.
ws.list_proxies() # calls API since it's more than 3s later
87
+
```
88
+
89
+
### Function Using Generic ProxyProvider
90
+
91
+
Since all proxy providers implement the same interface, we can make a function that allows us to easily swap out and utilize different providers. This is the main appeal of having a unified interface. It allows other modules to be provider agnostic, like my [TikTokAPI](https://github.com/davidteather/TikTok-Api) package.
92
+
93
+
```py
94
+
from proxyproviders import Webshare, ProxyProvider, ProxyConfig
95
+
96
+
defsome_function(provider: ProxyProvider):
97
+
proxies = provider.list_proxies()
98
+
print(proxies)
99
+
100
+
webshare = Webshare(api_key="your_api_key")
101
+
brightdata = BrightData(api_key="your_api_key")
102
+
103
+
some_function(webshare)
104
+
some_function(brightdata)
105
+
```
106
+
107
+
### Making Your Own Proxy Provider
108
+
109
+
Here's a skeleton of how you can make your very own `ProxyProvider` class. You'll need to implemenet all the required functions of the `ProxyProvider` which may be more than what's here at the time of writing.
110
+
111
+
If you do find yourself making one of these, consider contributing it back to the repository so everyone can use them :D
112
+
113
+
```py
114
+
from proxyproviders import ProxyProvider, ProxyConfig, Proxy
0 commit comments