summaryrefslogtreecommitdiff
path: root/docs/python.md
diff options
context:
space:
mode:
authorJan-Michael Brummer <jan.brummer@tabos.org>2023-03-07 15:21:02 +0100
committerJan-Michael Brummer <jan.brummer@tabos.org>2023-03-27 16:31:58 +0200
commit1752685aa329e434d0410a8d865722c294efe137 (patch)
tree1bf2dc3d56a0612e1d1d3b3a40518636d32fa86f /docs/python.md
parenta8ec41a5f13593db3ca16dc0d64a1d6e40590e81 (diff)
downloadlibproxy-git-1752685aa329e434d0410a8d865722c294efe137.tar.gz
Add samples (#64)
* Change Namespace to Libproxy * Add samples Fixes: https://github.com/janbrummer/libproxy2/issues/33
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")
+```
+