summaryrefslogtreecommitdiff
path: root/docs/python.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/python.md')
-rw-r--r--docs/python.md30
1 files changed, 30 insertions, 0 deletions
diff --git a/docs/python.md b/docs/python.md
new file mode 100644
index 0000000..8094e0b
--- /dev/null
+++ b/docs/python.md
@@ -0,0 +1,30 @@
+Title: How to use libproxy in Python
+Slug: snippets
+
+# How to use libproxy in Python
+
+```
+import gi
+gi.require_version('Libproxy', '1.0')
+from gi.repository import Libproxy
+import requests
+
+url = 'https://github.com/libproxy/libproxy'
+
+pf = Libproxy.ProxyFactory()
+proxies = pf.get_proxies(url)
+
+success = False
+for proxy in proxies:
+ response = requests.get(url) #, proxies=proxies)
+
+ if response.status_code == 200:
+ success = True
+ break
+
+if success:
+ print(f"The requested URL {url} could be retrieved using the current setup!")
+else:
+ print(f"The requested URL {url} could *NOT* be retrieved using the current setup")
+```
+