fetchly 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fetchly/__init__.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import time
|
|
3
|
+
|
|
4
|
+
default_headers={}
|
|
5
|
+
|
|
6
|
+
def set_headers(key):
|
|
7
|
+
default_headers .update(key)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get(url, timeout=10, retries=3, **kwargs):
|
|
14
|
+
kwargs.setdefault("headers", {}).update(default_headers)
|
|
15
|
+
for attempt in range(1, retries + 1):
|
|
16
|
+
try:
|
|
17
|
+
response = requests.get(url, timeout=timeout, **kwargs)
|
|
18
|
+
response.raise_for_status()
|
|
19
|
+
return response
|
|
20
|
+
except requests.exceptions.Timeout:
|
|
21
|
+
print(f"Attempt {attempt} timed out...")
|
|
22
|
+
except requests.exceptions.HTTPError as e:
|
|
23
|
+
raise Exception(f"HTTP error: {e}")
|
|
24
|
+
except requests.exceptions.ConnectionError:
|
|
25
|
+
print(f"Attempt {attempt} failed. Retrying...")
|
|
26
|
+
|
|
27
|
+
if attempt < retries:
|
|
28
|
+
time.sleep(2)
|
|
29
|
+
|
|
30
|
+
raise Exception(f"All {retries} attempts failed for {url}")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def post(url, timeout=10, retries=3, **kwargs):
|
|
34
|
+
kwargs.setdefault("headers", {}).update(default_headers)
|
|
35
|
+
for attempt in range(1, retries + 1):
|
|
36
|
+
try:
|
|
37
|
+
response = requests.post(url, timeout=timeout, **kwargs)
|
|
38
|
+
response.raise_for_status()
|
|
39
|
+
return response
|
|
40
|
+
except requests.exceptions.Timeout:
|
|
41
|
+
print(f"Attempt {attempt} timed out...")
|
|
42
|
+
except requests.exceptions.HTTPError as e:
|
|
43
|
+
raise Exception(f"HTTP error: {e}")
|
|
44
|
+
except requests.exceptions.ConnectionError:
|
|
45
|
+
print(f"Attempt {attempt} failed. Retrying...")
|
|
46
|
+
|
|
47
|
+
if attempt < retries:
|
|
48
|
+
time.sleep(2)
|
|
49
|
+
|
|
50
|
+
raise Exception(f"All {retries} attempts failed for {url}")
|
|
51
|
+
|
|
52
|
+
def put(url, timeout=10, retries=3, **kwargs):
|
|
53
|
+
kwargs.setdefault("headers", {}).update(default_headers)
|
|
54
|
+
for attempt in range(1, retries + 1):
|
|
55
|
+
try:
|
|
56
|
+
response = requests.put(url, timeout=timeout, **kwargs)
|
|
57
|
+
response.raise_for_status()
|
|
58
|
+
return response
|
|
59
|
+
except requests.exceptions.Timeout:
|
|
60
|
+
print(f"Attempt {attempt} timed out...")
|
|
61
|
+
except requests.exceptions.HTTPError as e:
|
|
62
|
+
raise Exception(f"HTTP error: {e}")
|
|
63
|
+
except requests.exceptions.ConnectionError:
|
|
64
|
+
print(f"Attempt {attempt} failed. Retrying...")
|
|
65
|
+
|
|
66
|
+
if attempt < retries:
|
|
67
|
+
time.sleep(2)
|
|
68
|
+
|
|
69
|
+
raise Exception(f"All {retries} attempts failed for {url}")
|
|
70
|
+
|
|
71
|
+
def delete(url, timeout=10, retries=3, **kwargs):
|
|
72
|
+
kwargs.setdefault("headers", {}).update(default_headers)
|
|
73
|
+
for attempt in range(1, retries + 1):
|
|
74
|
+
try:
|
|
75
|
+
response = requests.delete(url, timeout=timeout, **kwargs)
|
|
76
|
+
response.raise_for_status()
|
|
77
|
+
return response
|
|
78
|
+
except requests.exceptions.Timeout:
|
|
79
|
+
print(f"Attempt {attempt} timed out...")
|
|
80
|
+
except requests.exceptions.HTTPError as e:
|
|
81
|
+
raise Exception(f"HTTP error: {e}")
|
|
82
|
+
except requests.exceptions.ConnectionError:
|
|
83
|
+
print(f"Attempt {attempt} failed. Retrying...")
|
|
84
|
+
|
|
85
|
+
if attempt < retries:
|
|
86
|
+
time.sleep(2)
|
|
87
|
+
|
|
88
|
+
raise Exception(f"All {retries} attempts failed for {url}")
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fetchly
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A lightweight Python HTTP library with retries, timeouts, and automatic headers
|
|
5
|
+
Author: Sudhamsh Kalaonda
|
|
6
|
+
Author-email: sudhamshguptha14@gmail.com
|
|
7
|
+
Requires-Python: >=3.6
|
|
8
|
+
Requires-Dist: requests
|
|
9
|
+
Dynamic: author
|
|
10
|
+
Dynamic: author-email
|
|
11
|
+
Dynamic: requires-dist
|
|
12
|
+
Dynamic: requires-python
|
|
13
|
+
Dynamic: summary
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
fetchly/__init__.py,sha256=wii417VL1dIvUesfo49yUCqyJBkP6Ihf50rSWM-_Q8E,3069
|
|
2
|
+
fetchly-0.1.0.dist-info/METADATA,sha256=fqM1j7fdCc0jGw6Mvr2ikmiH2klEy7FXeVk6vwpkDiA,357
|
|
3
|
+
fetchly-0.1.0.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
|
|
4
|
+
fetchly-0.1.0.dist-info/top_level.txt,sha256=iN7F6Nlb_G8qQJfFN6Y53OYLqFWCrFyVlMMBgTqtE84,8
|
|
5
|
+
fetchly-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fetchly
|