apiverve-htmltotext 1.1.14__tar.gz
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.
- apiverve_htmltotext-1.1.14/LICENSE +21 -0
- apiverve_htmltotext-1.1.14/PKG-INFO +307 -0
- apiverve_htmltotext-1.1.14/README.md +262 -0
- apiverve_htmltotext-1.1.14/pyproject.toml +51 -0
- apiverve_htmltotext-1.1.14/setup.cfg +4 -0
- apiverve_htmltotext-1.1.14/src/apiverve_htmltotext/__init__.py +3 -0
- apiverve_htmltotext-1.1.14/src/apiverve_htmltotext/apiClient.py +250 -0
- apiverve_htmltotext-1.1.14/src/apiverve_htmltotext/exceptions.py +3 -0
- apiverve_htmltotext-1.1.14/src/apiverve_htmltotext/setup.py +26 -0
- apiverve_htmltotext-1.1.14/src/apiverve_htmltotext/setup_dep.py +21 -0
- apiverve_htmltotext-1.1.14/src/apiverve_htmltotext/tests/__init__.py +1 -0
- apiverve_htmltotext-1.1.14/src/apiverve_htmltotext/tests/test_api.py +19 -0
- apiverve_htmltotext-1.1.14/src/apiverve_htmltotext.egg-info/PKG-INFO +307 -0
- apiverve_htmltotext-1.1.14/src/apiverve_htmltotext.egg-info/SOURCES.txt +16 -0
- apiverve_htmltotext-1.1.14/src/apiverve_htmltotext.egg-info/dependency_links.txt +1 -0
- apiverve_htmltotext-1.1.14/src/apiverve_htmltotext.egg-info/requires.txt +1 -0
- apiverve_htmltotext-1.1.14/src/apiverve_htmltotext.egg-info/top_level.txt +1 -0
- apiverve_htmltotext-1.1.14/tests/test_api.py +27 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 APIVerve, and Evlar LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: apiverve-htmltotext
|
|
3
|
+
Version: 1.1.14
|
|
4
|
+
Summary: HTML to Text is a simple tool for converting HTML to text. It returns the text extracted from the HTML.
|
|
5
|
+
Author-email: APIVerve <hello@apiverve.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://apiverve.com?utm_source=pypi
|
|
8
|
+
Project-URL: Repository, https://github.com/apiverve/htmltotext-api
|
|
9
|
+
Project-URL: Documentation, https://docs.apiverve.com/api/htmltotext?utm_source=pypi
|
|
10
|
+
Project-URL: Twitter, https://twitter.com/apivervehq
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
16
|
+
Classifier: Intended Audience :: Healthcare Industry
|
|
17
|
+
Classifier: Intended Audience :: Education
|
|
18
|
+
Classifier: Intended Audience :: Science/Research
|
|
19
|
+
Classifier: Intended Audience :: Information Technology
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Topic :: Utilities
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering
|
|
23
|
+
Classifier: Topic :: Education
|
|
24
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
|
|
25
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Site Management
|
|
26
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
28
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
29
|
+
Classifier: Topic :: Internet
|
|
30
|
+
Classifier: Topic :: Communications
|
|
31
|
+
Classifier: Topic :: Office/Business
|
|
32
|
+
Classifier: Topic :: Text Processing
|
|
33
|
+
Classifier: Topic :: Security
|
|
34
|
+
Classifier: Topic :: Database
|
|
35
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
36
|
+
Classifier: Topic :: Software Development :: Pre-processors
|
|
37
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
38
|
+
Classifier: Topic :: Software Development :: Testing
|
|
39
|
+
Classifier: Natural Language :: English
|
|
40
|
+
Requires-Python: >=3.7
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
License-File: LICENSE
|
|
43
|
+
Requires-Dist: requests>=2.25.0
|
|
44
|
+
Dynamic: license-file
|
|
45
|
+
|
|
46
|
+
HTML to Text API
|
|
47
|
+
============
|
|
48
|
+
|
|
49
|
+
HTML to Text is a simple tool for converting HTML to text. It returns the text extracted from the HTML.
|
|
50
|
+
|
|
51
|
+

|
|
52
|
+

|
|
53
|
+

|
|
54
|
+
|
|
55
|
+
This is a Python API Wrapper for the [HTML to Text API](https://htmltotext.apiverve.com?utm_source=pypi&utm_medium=readme)
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
Using `pip`:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install apiverve-htmltotext
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Using `pip3`:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip3 install apiverve-htmltotext
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Configuration
|
|
76
|
+
|
|
77
|
+
Before using the htmltotext API client, you have to setup your account and obtain your API Key.
|
|
78
|
+
You can get it by signing up at [https://apiverve.com](https://apiverve.com?utm_source=pypi&utm_medium=readme)
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Quick Start
|
|
83
|
+
|
|
84
|
+
Here's a simple example to get you started quickly:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient
|
|
88
|
+
|
|
89
|
+
# Initialize the client with your APIVerve API key
|
|
90
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]")
|
|
91
|
+
|
|
92
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
93
|
+
|
|
94
|
+
try:
|
|
95
|
+
# Make the API call
|
|
96
|
+
result = api.execute(query)
|
|
97
|
+
|
|
98
|
+
# Print the result
|
|
99
|
+
print(result)
|
|
100
|
+
except Exception as e:
|
|
101
|
+
print(f"Error: {e}")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Usage
|
|
107
|
+
|
|
108
|
+
The HTML to Text API documentation is found here: [https://docs.apiverve.com/ref/htmltotext](https://docs.apiverve.com/ref/htmltotext?utm_source=pypi&utm_medium=readme).
|
|
109
|
+
You can find parameters, example responses, and status codes documented here.
|
|
110
|
+
|
|
111
|
+
### Setup
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
# Import the client module
|
|
115
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient
|
|
116
|
+
|
|
117
|
+
# Initialize the client with your APIVerve API key
|
|
118
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Perform Request
|
|
124
|
+
|
|
125
|
+
Using the API client, you can perform requests to the API.
|
|
126
|
+
|
|
127
|
+
###### Define Query
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
###### Simple Request
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
# Make a request to the API
|
|
137
|
+
result = api.execute(query)
|
|
138
|
+
|
|
139
|
+
# Print the result
|
|
140
|
+
print(result)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
###### Example Response
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"status": "ok",
|
|
148
|
+
"error": null,
|
|
149
|
+
"data": {
|
|
150
|
+
"text": "This is an example paragraph. Anything in the body tag will appear on the page, just like this p tag and its contents.",
|
|
151
|
+
"parsed": true,
|
|
152
|
+
"detectedLanguage": {
|
|
153
|
+
"language": "english",
|
|
154
|
+
"confidence": 0.3507446808510638
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Error Handling
|
|
163
|
+
|
|
164
|
+
The API client provides comprehensive error handling through the `HtmltotextAPIClientError` exception. Here are some examples:
|
|
165
|
+
|
|
166
|
+
### Basic Error Handling
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient, HtmltotextAPIClientError
|
|
170
|
+
|
|
171
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]")
|
|
172
|
+
|
|
173
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
174
|
+
|
|
175
|
+
try:
|
|
176
|
+
result = api.execute(query)
|
|
177
|
+
print("Success!")
|
|
178
|
+
print(result)
|
|
179
|
+
except HtmltotextAPIClientError as e:
|
|
180
|
+
print(f"API Error: {e.message}")
|
|
181
|
+
if e.status_code:
|
|
182
|
+
print(f"Status Code: {e.status_code}")
|
|
183
|
+
if e.response:
|
|
184
|
+
print(f"Response: {e.response}")
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Handling Specific Error Types
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient, HtmltotextAPIClientError
|
|
191
|
+
|
|
192
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]")
|
|
193
|
+
|
|
194
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
195
|
+
|
|
196
|
+
try:
|
|
197
|
+
result = api.execute(query)
|
|
198
|
+
|
|
199
|
+
# Check for successful response
|
|
200
|
+
if result.get('status') == 'success':
|
|
201
|
+
print("Request successful!")
|
|
202
|
+
print(result.get('data'))
|
|
203
|
+
else:
|
|
204
|
+
print(f"API returned an error: {result.get('error')}")
|
|
205
|
+
|
|
206
|
+
except HtmltotextAPIClientError as e:
|
|
207
|
+
# Handle API client errors
|
|
208
|
+
if e.status_code == 401:
|
|
209
|
+
print("Unauthorized: Invalid API key")
|
|
210
|
+
elif e.status_code == 429:
|
|
211
|
+
print("Rate limit exceeded")
|
|
212
|
+
elif e.status_code >= 500:
|
|
213
|
+
print("Server error - please try again later")
|
|
214
|
+
else:
|
|
215
|
+
print(f"API error: {e.message}")
|
|
216
|
+
except Exception as e:
|
|
217
|
+
# Handle unexpected errors
|
|
218
|
+
print(f"Unexpected error: {str(e)}")
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Using Context Manager (Recommended)
|
|
222
|
+
|
|
223
|
+
The client supports the context manager protocol for automatic resource cleanup:
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient, HtmltotextAPIClientError
|
|
227
|
+
|
|
228
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
229
|
+
|
|
230
|
+
# Using context manager ensures proper cleanup
|
|
231
|
+
with HtmltotextAPIClient("[YOUR_API_KEY]") as api:
|
|
232
|
+
try:
|
|
233
|
+
result = api.execute(query)
|
|
234
|
+
print(result)
|
|
235
|
+
except HtmltotextAPIClientError as e:
|
|
236
|
+
print(f"Error: {e.message}")
|
|
237
|
+
# Session is automatically closed here
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Advanced Features
|
|
243
|
+
|
|
244
|
+
### Debug Mode
|
|
245
|
+
|
|
246
|
+
Enable debug logging to see detailed request and response information:
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient
|
|
250
|
+
|
|
251
|
+
# Enable debug mode
|
|
252
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]", debug=True)
|
|
253
|
+
|
|
254
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
255
|
+
|
|
256
|
+
# Debug information will be printed to console
|
|
257
|
+
result = api.execute(query)
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Manual Session Management
|
|
261
|
+
|
|
262
|
+
If you need to manually manage the session lifecycle:
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient
|
|
266
|
+
|
|
267
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]")
|
|
268
|
+
|
|
269
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
270
|
+
|
|
271
|
+
try:
|
|
272
|
+
result = api.execute(query)
|
|
273
|
+
print(result)
|
|
274
|
+
finally:
|
|
275
|
+
# Manually close the session when done
|
|
276
|
+
api.close()
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## Customer Support
|
|
282
|
+
|
|
283
|
+
Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact?utm_source=pypi&utm_medium=readme).
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## Updates
|
|
288
|
+
Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## Legal
|
|
293
|
+
|
|
294
|
+
All usage of the APIVerve website, API, and services is subject to the [APIVerve Terms of Service](https://apiverve.com/terms?utm_source=pypi&utm_medium=readme) and all legal documents and agreements.
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## License
|
|
299
|
+
Licensed under the The MIT License (MIT)
|
|
300
|
+
|
|
301
|
+
Copyright (©) 2026 APIVerve, and EvlarSoft LLC
|
|
302
|
+
|
|
303
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
304
|
+
|
|
305
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
306
|
+
|
|
307
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
HTML to Text API
|
|
2
|
+
============
|
|
3
|
+
|
|
4
|
+
HTML to Text is a simple tool for converting HTML to text. It returns the text extracted from the HTML.
|
|
5
|
+
|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
This is a Python API Wrapper for the [HTML to Text API](https://htmltotext.apiverve.com?utm_source=pypi&utm_medium=readme)
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Using `pip`:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install apiverve-htmltotext
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Using `pip3`:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip3 install apiverve-htmltotext
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Configuration
|
|
31
|
+
|
|
32
|
+
Before using the htmltotext API client, you have to setup your account and obtain your API Key.
|
|
33
|
+
You can get it by signing up at [https://apiverve.com](https://apiverve.com?utm_source=pypi&utm_medium=readme)
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
Here's a simple example to get you started quickly:
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient
|
|
43
|
+
|
|
44
|
+
# Initialize the client with your APIVerve API key
|
|
45
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]")
|
|
46
|
+
|
|
47
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
48
|
+
|
|
49
|
+
try:
|
|
50
|
+
# Make the API call
|
|
51
|
+
result = api.execute(query)
|
|
52
|
+
|
|
53
|
+
# Print the result
|
|
54
|
+
print(result)
|
|
55
|
+
except Exception as e:
|
|
56
|
+
print(f"Error: {e}")
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
The HTML to Text API documentation is found here: [https://docs.apiverve.com/ref/htmltotext](https://docs.apiverve.com/ref/htmltotext?utm_source=pypi&utm_medium=readme).
|
|
64
|
+
You can find parameters, example responses, and status codes documented here.
|
|
65
|
+
|
|
66
|
+
### Setup
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
# Import the client module
|
|
70
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient
|
|
71
|
+
|
|
72
|
+
# Initialize the client with your APIVerve API key
|
|
73
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]")
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Perform Request
|
|
79
|
+
|
|
80
|
+
Using the API client, you can perform requests to the API.
|
|
81
|
+
|
|
82
|
+
###### Define Query
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
###### Simple Request
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
# Make a request to the API
|
|
92
|
+
result = api.execute(query)
|
|
93
|
+
|
|
94
|
+
# Print the result
|
|
95
|
+
print(result)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
###### Example Response
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"status": "ok",
|
|
103
|
+
"error": null,
|
|
104
|
+
"data": {
|
|
105
|
+
"text": "This is an example paragraph. Anything in the body tag will appear on the page, just like this p tag and its contents.",
|
|
106
|
+
"parsed": true,
|
|
107
|
+
"detectedLanguage": {
|
|
108
|
+
"language": "english",
|
|
109
|
+
"confidence": 0.3507446808510638
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Error Handling
|
|
118
|
+
|
|
119
|
+
The API client provides comprehensive error handling through the `HtmltotextAPIClientError` exception. Here are some examples:
|
|
120
|
+
|
|
121
|
+
### Basic Error Handling
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient, HtmltotextAPIClientError
|
|
125
|
+
|
|
126
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]")
|
|
127
|
+
|
|
128
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
129
|
+
|
|
130
|
+
try:
|
|
131
|
+
result = api.execute(query)
|
|
132
|
+
print("Success!")
|
|
133
|
+
print(result)
|
|
134
|
+
except HtmltotextAPIClientError as e:
|
|
135
|
+
print(f"API Error: {e.message}")
|
|
136
|
+
if e.status_code:
|
|
137
|
+
print(f"Status Code: {e.status_code}")
|
|
138
|
+
if e.response:
|
|
139
|
+
print(f"Response: {e.response}")
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Handling Specific Error Types
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient, HtmltotextAPIClientError
|
|
146
|
+
|
|
147
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]")
|
|
148
|
+
|
|
149
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
150
|
+
|
|
151
|
+
try:
|
|
152
|
+
result = api.execute(query)
|
|
153
|
+
|
|
154
|
+
# Check for successful response
|
|
155
|
+
if result.get('status') == 'success':
|
|
156
|
+
print("Request successful!")
|
|
157
|
+
print(result.get('data'))
|
|
158
|
+
else:
|
|
159
|
+
print(f"API returned an error: {result.get('error')}")
|
|
160
|
+
|
|
161
|
+
except HtmltotextAPIClientError as e:
|
|
162
|
+
# Handle API client errors
|
|
163
|
+
if e.status_code == 401:
|
|
164
|
+
print("Unauthorized: Invalid API key")
|
|
165
|
+
elif e.status_code == 429:
|
|
166
|
+
print("Rate limit exceeded")
|
|
167
|
+
elif e.status_code >= 500:
|
|
168
|
+
print("Server error - please try again later")
|
|
169
|
+
else:
|
|
170
|
+
print(f"API error: {e.message}")
|
|
171
|
+
except Exception as e:
|
|
172
|
+
# Handle unexpected errors
|
|
173
|
+
print(f"Unexpected error: {str(e)}")
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Using Context Manager (Recommended)
|
|
177
|
+
|
|
178
|
+
The client supports the context manager protocol for automatic resource cleanup:
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient, HtmltotextAPIClientError
|
|
182
|
+
|
|
183
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
184
|
+
|
|
185
|
+
# Using context manager ensures proper cleanup
|
|
186
|
+
with HtmltotextAPIClient("[YOUR_API_KEY]") as api:
|
|
187
|
+
try:
|
|
188
|
+
result = api.execute(query)
|
|
189
|
+
print(result)
|
|
190
|
+
except HtmltotextAPIClientError as e:
|
|
191
|
+
print(f"Error: {e.message}")
|
|
192
|
+
# Session is automatically closed here
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Advanced Features
|
|
198
|
+
|
|
199
|
+
### Debug Mode
|
|
200
|
+
|
|
201
|
+
Enable debug logging to see detailed request and response information:
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient
|
|
205
|
+
|
|
206
|
+
# Enable debug mode
|
|
207
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]", debug=True)
|
|
208
|
+
|
|
209
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
210
|
+
|
|
211
|
+
# Debug information will be printed to console
|
|
212
|
+
result = api.execute(query)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Manual Session Management
|
|
216
|
+
|
|
217
|
+
If you need to manually manage the session lifecycle:
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient
|
|
221
|
+
|
|
222
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]")
|
|
223
|
+
|
|
224
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
225
|
+
|
|
226
|
+
try:
|
|
227
|
+
result = api.execute(query)
|
|
228
|
+
print(result)
|
|
229
|
+
finally:
|
|
230
|
+
# Manually close the session when done
|
|
231
|
+
api.close()
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
## Customer Support
|
|
237
|
+
|
|
238
|
+
Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact?utm_source=pypi&utm_medium=readme).
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Updates
|
|
243
|
+
Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Legal
|
|
248
|
+
|
|
249
|
+
All usage of the APIVerve website, API, and services is subject to the [APIVerve Terms of Service](https://apiverve.com/terms?utm_source=pypi&utm_medium=readme) and all legal documents and agreements.
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## License
|
|
254
|
+
Licensed under the The MIT License (MIT)
|
|
255
|
+
|
|
256
|
+
Copyright (©) 2026 APIVerve, and EvlarSoft LLC
|
|
257
|
+
|
|
258
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
259
|
+
|
|
260
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
261
|
+
|
|
262
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "apiverve-htmltotext"
|
|
3
|
+
version = "1.1.14"
|
|
4
|
+
authors = [
|
|
5
|
+
{ name="APIVerve", email="hello@apiverve.com" },
|
|
6
|
+
]
|
|
7
|
+
description = "HTML to Text is a simple tool for converting HTML to text. It returns the text extracted from the HTML."
|
|
8
|
+
keywords = []
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.7"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
dependencies = [
|
|
13
|
+
"requests>=2.25.0"
|
|
14
|
+
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 5 - Production/Stable",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Intended Audience :: Financial and Insurance Industry",
|
|
21
|
+
"Intended Audience :: Healthcare Industry",
|
|
22
|
+
"Intended Audience :: Education",
|
|
23
|
+
"Intended Audience :: Science/Research",
|
|
24
|
+
"Intended Audience :: Information Technology",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
"Topic :: Utilities",
|
|
27
|
+
"Topic :: Scientific/Engineering",
|
|
28
|
+
"Topic :: Education",
|
|
29
|
+
"Topic :: Internet :: WWW/HTTP :: Indexing/Search",
|
|
30
|
+
"Topic :: Internet :: WWW/HTTP :: Site Management",
|
|
31
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
32
|
+
"Topic :: Software Development :: Libraries",
|
|
33
|
+
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
|
34
|
+
"Topic :: Internet",
|
|
35
|
+
"Topic :: Communications",
|
|
36
|
+
"Topic :: Office/Business",
|
|
37
|
+
"Topic :: Text Processing",
|
|
38
|
+
"Topic :: Security",
|
|
39
|
+
"Topic :: Database",
|
|
40
|
+
"Topic :: Software Development :: Code Generators",
|
|
41
|
+
"Topic :: Software Development :: Pre-processors",
|
|
42
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
43
|
+
"Topic :: Software Development :: Testing",
|
|
44
|
+
"Natural Language :: English",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[project.urls]
|
|
48
|
+
Homepage = "https://apiverve.com?utm_source=pypi"
|
|
49
|
+
Repository = "https://github.com/apiverve/htmltotext-api"
|
|
50
|
+
Documentation = "https://docs.apiverve.com/api/htmltotext?utm_source=pypi"
|
|
51
|
+
Twitter = "https://twitter.com/apivervehq"
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from typing import Dict, Optional, Any
|
|
3
|
+
from dataclasses import dataclass, List
|
|
4
|
+
import requests
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class HtmltotextAPIClientError(Exception):
|
|
8
|
+
"""Custom exception for API client errors"""
|
|
9
|
+
def __init__(self, message: str, status_code: Optional[int] = None, response: Optional[Dict] = None):
|
|
10
|
+
self.message = message
|
|
11
|
+
self.status_code = status_code
|
|
12
|
+
self.response = response
|
|
13
|
+
super().__init__(self.message)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ValidationError(HtmltotextAPIClientError):
|
|
17
|
+
"""Custom exception for parameter validation errors"""
|
|
18
|
+
def __init__(self, errors: List[str]):
|
|
19
|
+
self.errors = errors
|
|
20
|
+
message = f"Validation failed: {' '.join(errors)}"
|
|
21
|
+
super().__init__(message)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class HtmltotextAPIClient:
|
|
25
|
+
# Validation rules for parameters (generated from schema)
|
|
26
|
+
VALIDATION_RULES = {
|
|
27
|
+
"html": {"type": "string", "required": True}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
# Format validation patterns
|
|
31
|
+
FORMAT_PATTERNS = {
|
|
32
|
+
'email': r'^[^\s@]+@[^\s@]+\.[^\s@]+$',
|
|
33
|
+
'url': r'^https?://.+',
|
|
34
|
+
'ip': r'^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$',
|
|
35
|
+
'date': r'^\d{4}-\d{2}-\d{2}$',
|
|
36
|
+
'hexColor': r'^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
def __init__(self, api_key: str, secure: bool = True, debug: bool = False):
|
|
40
|
+
"""
|
|
41
|
+
Initialize the HtmltotextAPIClient with the API key and optional settings
|
|
42
|
+
|
|
43
|
+
:param api_key: Your APIVerve API key
|
|
44
|
+
:param secure: Deprecated. Always set to True
|
|
45
|
+
:param debug: Enable debug logging (default: False)
|
|
46
|
+
:raises HtmltotextAPIClientError: If API key is invalid
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
self._validate_api_key(api_key)
|
|
50
|
+
|
|
51
|
+
self.api_key = api_key
|
|
52
|
+
self.secure = secure
|
|
53
|
+
self.debug = debug
|
|
54
|
+
self.base_url = 'https://api.apiverve.com/v1/htmltotext'
|
|
55
|
+
self.headers = {
|
|
56
|
+
'x-api-key': self.api_key,
|
|
57
|
+
'auth-mode': 'pypi-package'
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
# Create a session for connection pooling
|
|
61
|
+
self.session = requests.Session()
|
|
62
|
+
self.session.headers.update(self.headers)
|
|
63
|
+
|
|
64
|
+
def _validate_api_key(self, api_key: str) -> None:
|
|
65
|
+
"""
|
|
66
|
+
Validate the API key format
|
|
67
|
+
|
|
68
|
+
:param api_key: API key to validate
|
|
69
|
+
:raises HtmltotextAPIClientError: If API key is invalid
|
|
70
|
+
"""
|
|
71
|
+
if not api_key or not api_key.strip():
|
|
72
|
+
raise HtmltotextAPIClientError(
|
|
73
|
+
"API key is required. Get your API key at: https://apiverve.com"
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# Check format (GUID, prefixed keys like apv_xxx, or alphanumeric)
|
|
77
|
+
if not re.match(r'^[a-zA-Z0-9_-]+$', api_key):
|
|
78
|
+
raise HtmltotextAPIClientError(
|
|
79
|
+
"Invalid API key format. API key should only contain letters, numbers, hyphens, and underscores. "
|
|
80
|
+
"Get your API key at: https://apiverve.com"
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
def _log(self, message: str) -> None:
|
|
84
|
+
"""
|
|
85
|
+
Log a debug message if debug mode is enabled
|
|
86
|
+
|
|
87
|
+
:param message: Message to log
|
|
88
|
+
"""
|
|
89
|
+
if self.debug:
|
|
90
|
+
print(f"[HtmltotextAPIClient DEBUG] {message}")
|
|
91
|
+
|
|
92
|
+
def _validate_params(self, params: Optional[Dict[str, Any]]) -> None:
|
|
93
|
+
"""
|
|
94
|
+
Validate parameters against schema rules
|
|
95
|
+
|
|
96
|
+
:param params: Parameters to validate
|
|
97
|
+
:raises ValidationError: If validation fails
|
|
98
|
+
"""
|
|
99
|
+
if not self.VALIDATION_RULES:
|
|
100
|
+
return
|
|
101
|
+
|
|
102
|
+
errors = []
|
|
103
|
+
params = params or {}
|
|
104
|
+
|
|
105
|
+
for param_name, rules in self.VALIDATION_RULES.items():
|
|
106
|
+
value = params.get(param_name)
|
|
107
|
+
|
|
108
|
+
# Check required
|
|
109
|
+
if rules.get('required') and (value is None or value == ''):
|
|
110
|
+
errors.append(f"Required parameter [{param_name}] is missing.")
|
|
111
|
+
continue
|
|
112
|
+
|
|
113
|
+
# Skip validation if value is not provided and not required
|
|
114
|
+
if value is None:
|
|
115
|
+
continue
|
|
116
|
+
|
|
117
|
+
param_type = rules.get('type', 'string')
|
|
118
|
+
|
|
119
|
+
# Type validation
|
|
120
|
+
if param_type in ('integer', 'number'):
|
|
121
|
+
try:
|
|
122
|
+
num_value = float(value) if param_type == 'number' else int(value)
|
|
123
|
+
|
|
124
|
+
# Min/max validation
|
|
125
|
+
if 'min' in rules and num_value < rules['min']:
|
|
126
|
+
errors.append(f"Parameter [{param_name}] must be at least {rules['min']}.")
|
|
127
|
+
if 'max' in rules and num_value > rules['max']:
|
|
128
|
+
errors.append(f"Parameter [{param_name}] must be at most {rules['max']}.")
|
|
129
|
+
except (ValueError, TypeError):
|
|
130
|
+
errors.append(f"Parameter [{param_name}] must be a valid {param_type}.")
|
|
131
|
+
continue
|
|
132
|
+
|
|
133
|
+
elif param_type == 'string':
|
|
134
|
+
if not isinstance(value, str):
|
|
135
|
+
errors.append(f"Parameter [{param_name}] must be a string.")
|
|
136
|
+
continue
|
|
137
|
+
|
|
138
|
+
# Length validation
|
|
139
|
+
if 'minLength' in rules and len(value) < rules['minLength']:
|
|
140
|
+
errors.append(f"Parameter [{param_name}] must be at least {rules['minLength']} characters.")
|
|
141
|
+
if 'maxLength' in rules and len(value) > rules['maxLength']:
|
|
142
|
+
errors.append(f"Parameter [{param_name}] must be at most {rules['maxLength']} characters.")
|
|
143
|
+
|
|
144
|
+
# Format validation
|
|
145
|
+
if 'format' in rules and rules['format'] in self.FORMAT_PATTERNS:
|
|
146
|
+
pattern = self.FORMAT_PATTERNS[rules['format']]
|
|
147
|
+
if not re.match(pattern, value, re.IGNORECASE):
|
|
148
|
+
errors.append(f"Parameter [{param_name}] must be a valid {rules['format']}.")
|
|
149
|
+
|
|
150
|
+
elif param_type == 'boolean':
|
|
151
|
+
if not isinstance(value, bool) and value not in ('true', 'false', True, False):
|
|
152
|
+
errors.append(f"Parameter [{param_name}] must be a boolean.")
|
|
153
|
+
|
|
154
|
+
elif param_type == 'array':
|
|
155
|
+
if not isinstance(value, list):
|
|
156
|
+
errors.append(f"Parameter [{param_name}] must be an array.")
|
|
157
|
+
|
|
158
|
+
# Enum validation
|
|
159
|
+
if 'enum' in rules and value not in rules['enum']:
|
|
160
|
+
errors.append(f"Parameter [{param_name}] must be one of: {', '.join(map(str, rules['enum']))}.")
|
|
161
|
+
|
|
162
|
+
if errors:
|
|
163
|
+
raise ValidationError(errors)
|
|
164
|
+
|
|
165
|
+
def execute(self, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]: # Returns HTMLtoTextData in 'data' field
|
|
166
|
+
"""
|
|
167
|
+
Execute the API request
|
|
168
|
+
|
|
169
|
+
:param params: API parameters (optional)
|
|
170
|
+
:return: API response as a dictionary
|
|
171
|
+
:raises HtmltotextAPIClientError: If the request fails or returns an error
|
|
172
|
+
:raises ValidationError: If parameter validation fails
|
|
173
|
+
"""
|
|
174
|
+
|
|
175
|
+
# Validate parameters against schema rules
|
|
176
|
+
self._validate_params(params)
|
|
177
|
+
|
|
178
|
+
method = "POST"
|
|
179
|
+
|
|
180
|
+
self._log(f"Making {method} request to {self.base_url}")
|
|
181
|
+
if params:
|
|
182
|
+
self._log(f"Parameters: {params}")
|
|
183
|
+
|
|
184
|
+
try:
|
|
185
|
+
if method.upper() == 'POST':
|
|
186
|
+
self._log("Sending POST request with JSON body")
|
|
187
|
+
response = self.session.post(self.base_url, json=params, timeout=30)
|
|
188
|
+
else:
|
|
189
|
+
self._log("Sending GET request with query parameters")
|
|
190
|
+
response = self.session.get(self.base_url, params=params, timeout=30)
|
|
191
|
+
|
|
192
|
+
self._log(f"Response status code: {response.status_code}")
|
|
193
|
+
|
|
194
|
+
# Try to parse JSON response
|
|
195
|
+
try:
|
|
196
|
+
response_data = response.json()
|
|
197
|
+
except ValueError as e:
|
|
198
|
+
raise HtmltotextAPIClientError(
|
|
199
|
+
f"Invalid JSON response from API: {str(e)}",
|
|
200
|
+
status_code=response.status_code
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
# Check for API-level errors in the response
|
|
204
|
+
if response_data.get('status') == 'error':
|
|
205
|
+
error_message = response_data.get('error', 'Unknown API error')
|
|
206
|
+
self._log(f"API returned error: {error_message}")
|
|
207
|
+
raise HtmltotextAPIClientError(
|
|
208
|
+
error_message,
|
|
209
|
+
status_code=response.status_code,
|
|
210
|
+
response=response_data
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
# Check HTTP status code
|
|
214
|
+
if not response.ok:
|
|
215
|
+
error_message = response_data.get('error', f"HTTP {response.status_code} error")
|
|
216
|
+
self._log(f"HTTP error: {error_message}")
|
|
217
|
+
raise HtmltotextAPIClientError(
|
|
218
|
+
error_message,
|
|
219
|
+
status_code=response.status_code,
|
|
220
|
+
response=response_data
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
self._log("Request successful")
|
|
224
|
+
return response_data
|
|
225
|
+
|
|
226
|
+
except requests.exceptions.Timeout as e:
|
|
227
|
+
self._log(f"Request timeout: {str(e)}")
|
|
228
|
+
raise HtmltotextAPIClientError(f"Request timeout: {str(e)}")
|
|
229
|
+
except requests.exceptions.ConnectionError as e:
|
|
230
|
+
self._log(f"Connection error: {str(e)}")
|
|
231
|
+
raise HtmltotextAPIClientError(f"Connection error: {str(e)}")
|
|
232
|
+
except requests.exceptions.RequestException as e:
|
|
233
|
+
self._log(f"Request exception: {str(e)}")
|
|
234
|
+
raise HtmltotextAPIClientError(f"Request failed: {str(e)}")
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def close(self) -> None:
|
|
238
|
+
"""
|
|
239
|
+
Close the session and release resources
|
|
240
|
+
"""
|
|
241
|
+
self._log("Closing session")
|
|
242
|
+
self.session.close()
|
|
243
|
+
|
|
244
|
+
def __enter__(self):
|
|
245
|
+
"""Context manager entry"""
|
|
246
|
+
return self
|
|
247
|
+
|
|
248
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
249
|
+
"""Context manager exit"""
|
|
250
|
+
self.close()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
lib_folder = os.path.dirname(os.path.realpath(__file__))
|
|
5
|
+
requirements_file = os.path.join(lib_folder, 'requirements.txt')
|
|
6
|
+
install_requires = ["requests >= 2.25.1", "setuptools >= 56.0.0"]
|
|
7
|
+
if os.path.exists(requirements_file):
|
|
8
|
+
with open(requirements_file, 'r') as f:
|
|
9
|
+
install_requires = f.read().splitlines()
|
|
10
|
+
|
|
11
|
+
setup(
|
|
12
|
+
name='apiverve_htmltotext',
|
|
13
|
+
version='1.1.14',
|
|
14
|
+
packages=find_packages(),
|
|
15
|
+
include_package_data=True,
|
|
16
|
+
install_requires=install_requires,
|
|
17
|
+
description='HTML to Text is a simple tool for converting HTML to text. It returns the text extracted from the HTML.',
|
|
18
|
+
author='APIVerve',
|
|
19
|
+
author_email='hello@apiverve.com',
|
|
20
|
+
url='https://htmltotext.apiverve.com?utm_source=pypi&utm_medium=homepage',
|
|
21
|
+
classifiers=[
|
|
22
|
+
'Programming Language :: Python :: 3',
|
|
23
|
+
'Operating System :: OS Independent',
|
|
24
|
+
],
|
|
25
|
+
python_requires='>=3.6',
|
|
26
|
+
)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name='apiverve_htmltotext',
|
|
5
|
+
version='1.1.14',
|
|
6
|
+
packages=find_packages(),
|
|
7
|
+
include_package_data=True,
|
|
8
|
+
install_requires=[
|
|
9
|
+
'requests',
|
|
10
|
+
'setuptools'
|
|
11
|
+
],
|
|
12
|
+
description='HTML to Text is a simple tool for converting HTML to text. It returns the text extracted from the HTML.',
|
|
13
|
+
author='APIVerve',
|
|
14
|
+
author_email='hello@apiverve.com',
|
|
15
|
+
url='https://htmltotext.apiverve.com?utm_source=pypi&utm_medium=homepage',
|
|
16
|
+
classifiers=[
|
|
17
|
+
'Programming Language :: Python :: 3',
|
|
18
|
+
'Operating System :: OS Independent',
|
|
19
|
+
],
|
|
20
|
+
python_requires='>=3.6',
|
|
21
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Initialize test module
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient
|
|
3
|
+
|
|
4
|
+
class TestClient(unittest.TestCase):
|
|
5
|
+
|
|
6
|
+
def setUp(self):
|
|
7
|
+
self.api_key = 'test_api_key'
|
|
8
|
+
self.client = HtmltotextAPIClient(self.api_key)
|
|
9
|
+
|
|
10
|
+
def test_get(self):
|
|
11
|
+
# Assuming there's an endpoint 'test_endpoint' for testing purposes
|
|
12
|
+
try:
|
|
13
|
+
response = self.client.get('test_endpoint')
|
|
14
|
+
self.assertIsInstance(response, dict)
|
|
15
|
+
except Exception as e:
|
|
16
|
+
self.fail(f"GET request failed with exception {e}")
|
|
17
|
+
|
|
18
|
+
if __name__ == '__main__':
|
|
19
|
+
unittest.main()
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: apiverve-htmltotext
|
|
3
|
+
Version: 1.1.14
|
|
4
|
+
Summary: HTML to Text is a simple tool for converting HTML to text. It returns the text extracted from the HTML.
|
|
5
|
+
Author-email: APIVerve <hello@apiverve.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://apiverve.com?utm_source=pypi
|
|
8
|
+
Project-URL: Repository, https://github.com/apiverve/htmltotext-api
|
|
9
|
+
Project-URL: Documentation, https://docs.apiverve.com/api/htmltotext?utm_source=pypi
|
|
10
|
+
Project-URL: Twitter, https://twitter.com/apivervehq
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
16
|
+
Classifier: Intended Audience :: Healthcare Industry
|
|
17
|
+
Classifier: Intended Audience :: Education
|
|
18
|
+
Classifier: Intended Audience :: Science/Research
|
|
19
|
+
Classifier: Intended Audience :: Information Technology
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Topic :: Utilities
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering
|
|
23
|
+
Classifier: Topic :: Education
|
|
24
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
|
|
25
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Site Management
|
|
26
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
27
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
28
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
29
|
+
Classifier: Topic :: Internet
|
|
30
|
+
Classifier: Topic :: Communications
|
|
31
|
+
Classifier: Topic :: Office/Business
|
|
32
|
+
Classifier: Topic :: Text Processing
|
|
33
|
+
Classifier: Topic :: Security
|
|
34
|
+
Classifier: Topic :: Database
|
|
35
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
36
|
+
Classifier: Topic :: Software Development :: Pre-processors
|
|
37
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
38
|
+
Classifier: Topic :: Software Development :: Testing
|
|
39
|
+
Classifier: Natural Language :: English
|
|
40
|
+
Requires-Python: >=3.7
|
|
41
|
+
Description-Content-Type: text/markdown
|
|
42
|
+
License-File: LICENSE
|
|
43
|
+
Requires-Dist: requests>=2.25.0
|
|
44
|
+
Dynamic: license-file
|
|
45
|
+
|
|
46
|
+
HTML to Text API
|
|
47
|
+
============
|
|
48
|
+
|
|
49
|
+
HTML to Text is a simple tool for converting HTML to text. It returns the text extracted from the HTML.
|
|
50
|
+
|
|
51
|
+

|
|
52
|
+

|
|
53
|
+

|
|
54
|
+
|
|
55
|
+
This is a Python API Wrapper for the [HTML to Text API](https://htmltotext.apiverve.com?utm_source=pypi&utm_medium=readme)
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
Using `pip`:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install apiverve-htmltotext
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Using `pip3`:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip3 install apiverve-htmltotext
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Configuration
|
|
76
|
+
|
|
77
|
+
Before using the htmltotext API client, you have to setup your account and obtain your API Key.
|
|
78
|
+
You can get it by signing up at [https://apiverve.com](https://apiverve.com?utm_source=pypi&utm_medium=readme)
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Quick Start
|
|
83
|
+
|
|
84
|
+
Here's a simple example to get you started quickly:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient
|
|
88
|
+
|
|
89
|
+
# Initialize the client with your APIVerve API key
|
|
90
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]")
|
|
91
|
+
|
|
92
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
93
|
+
|
|
94
|
+
try:
|
|
95
|
+
# Make the API call
|
|
96
|
+
result = api.execute(query)
|
|
97
|
+
|
|
98
|
+
# Print the result
|
|
99
|
+
print(result)
|
|
100
|
+
except Exception as e:
|
|
101
|
+
print(f"Error: {e}")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## Usage
|
|
107
|
+
|
|
108
|
+
The HTML to Text API documentation is found here: [https://docs.apiverve.com/ref/htmltotext](https://docs.apiverve.com/ref/htmltotext?utm_source=pypi&utm_medium=readme).
|
|
109
|
+
You can find parameters, example responses, and status codes documented here.
|
|
110
|
+
|
|
111
|
+
### Setup
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
# Import the client module
|
|
115
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient
|
|
116
|
+
|
|
117
|
+
# Initialize the client with your APIVerve API key
|
|
118
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Perform Request
|
|
124
|
+
|
|
125
|
+
Using the API client, you can perform requests to the API.
|
|
126
|
+
|
|
127
|
+
###### Define Query
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
###### Simple Request
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
# Make a request to the API
|
|
137
|
+
result = api.execute(query)
|
|
138
|
+
|
|
139
|
+
# Print the result
|
|
140
|
+
print(result)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
###### Example Response
|
|
144
|
+
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"status": "ok",
|
|
148
|
+
"error": null,
|
|
149
|
+
"data": {
|
|
150
|
+
"text": "This is an example paragraph. Anything in the body tag will appear on the page, just like this p tag and its contents.",
|
|
151
|
+
"parsed": true,
|
|
152
|
+
"detectedLanguage": {
|
|
153
|
+
"language": "english",
|
|
154
|
+
"confidence": 0.3507446808510638
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Error Handling
|
|
163
|
+
|
|
164
|
+
The API client provides comprehensive error handling through the `HtmltotextAPIClientError` exception. Here are some examples:
|
|
165
|
+
|
|
166
|
+
### Basic Error Handling
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient, HtmltotextAPIClientError
|
|
170
|
+
|
|
171
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]")
|
|
172
|
+
|
|
173
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
174
|
+
|
|
175
|
+
try:
|
|
176
|
+
result = api.execute(query)
|
|
177
|
+
print("Success!")
|
|
178
|
+
print(result)
|
|
179
|
+
except HtmltotextAPIClientError as e:
|
|
180
|
+
print(f"API Error: {e.message}")
|
|
181
|
+
if e.status_code:
|
|
182
|
+
print(f"Status Code: {e.status_code}")
|
|
183
|
+
if e.response:
|
|
184
|
+
print(f"Response: {e.response}")
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Handling Specific Error Types
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient, HtmltotextAPIClientError
|
|
191
|
+
|
|
192
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]")
|
|
193
|
+
|
|
194
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
195
|
+
|
|
196
|
+
try:
|
|
197
|
+
result = api.execute(query)
|
|
198
|
+
|
|
199
|
+
# Check for successful response
|
|
200
|
+
if result.get('status') == 'success':
|
|
201
|
+
print("Request successful!")
|
|
202
|
+
print(result.get('data'))
|
|
203
|
+
else:
|
|
204
|
+
print(f"API returned an error: {result.get('error')}")
|
|
205
|
+
|
|
206
|
+
except HtmltotextAPIClientError as e:
|
|
207
|
+
# Handle API client errors
|
|
208
|
+
if e.status_code == 401:
|
|
209
|
+
print("Unauthorized: Invalid API key")
|
|
210
|
+
elif e.status_code == 429:
|
|
211
|
+
print("Rate limit exceeded")
|
|
212
|
+
elif e.status_code >= 500:
|
|
213
|
+
print("Server error - please try again later")
|
|
214
|
+
else:
|
|
215
|
+
print(f"API error: {e.message}")
|
|
216
|
+
except Exception as e:
|
|
217
|
+
# Handle unexpected errors
|
|
218
|
+
print(f"Unexpected error: {str(e)}")
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Using Context Manager (Recommended)
|
|
222
|
+
|
|
223
|
+
The client supports the context manager protocol for automatic resource cleanup:
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient, HtmltotextAPIClientError
|
|
227
|
+
|
|
228
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
229
|
+
|
|
230
|
+
# Using context manager ensures proper cleanup
|
|
231
|
+
with HtmltotextAPIClient("[YOUR_API_KEY]") as api:
|
|
232
|
+
try:
|
|
233
|
+
result = api.execute(query)
|
|
234
|
+
print(result)
|
|
235
|
+
except HtmltotextAPIClientError as e:
|
|
236
|
+
print(f"Error: {e.message}")
|
|
237
|
+
# Session is automatically closed here
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Advanced Features
|
|
243
|
+
|
|
244
|
+
### Debug Mode
|
|
245
|
+
|
|
246
|
+
Enable debug logging to see detailed request and response information:
|
|
247
|
+
|
|
248
|
+
```python
|
|
249
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient
|
|
250
|
+
|
|
251
|
+
# Enable debug mode
|
|
252
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]", debug=True)
|
|
253
|
+
|
|
254
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
255
|
+
|
|
256
|
+
# Debug information will be printed to console
|
|
257
|
+
result = api.execute(query)
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### Manual Session Management
|
|
261
|
+
|
|
262
|
+
If you need to manually manage the session lifecycle:
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient
|
|
266
|
+
|
|
267
|
+
api = HtmltotextAPIClient("[YOUR_API_KEY]")
|
|
268
|
+
|
|
269
|
+
query = { "html": "<!doctype html> <html> <head> <title>This is the title of the webpage!</title> </head> <body> <p>This is an example paragraph. Anything in the <strong>body</strong> tag will appear on the page, just like this <strong>p</strong> tag and its contents.</p> </body> </html>" }
|
|
270
|
+
|
|
271
|
+
try:
|
|
272
|
+
result = api.execute(query)
|
|
273
|
+
print(result)
|
|
274
|
+
finally:
|
|
275
|
+
# Manually close the session when done
|
|
276
|
+
api.close()
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## Customer Support
|
|
282
|
+
|
|
283
|
+
Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact?utm_source=pypi&utm_medium=readme).
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## Updates
|
|
288
|
+
Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## Legal
|
|
293
|
+
|
|
294
|
+
All usage of the APIVerve website, API, and services is subject to the [APIVerve Terms of Service](https://apiverve.com/terms?utm_source=pypi&utm_medium=readme) and all legal documents and agreements.
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## License
|
|
299
|
+
Licensed under the The MIT License (MIT)
|
|
300
|
+
|
|
301
|
+
Copyright (©) 2026 APIVerve, and EvlarSoft LLC
|
|
302
|
+
|
|
303
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
304
|
+
|
|
305
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
306
|
+
|
|
307
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/apiverve_htmltotext/__init__.py
|
|
5
|
+
src/apiverve_htmltotext/apiClient.py
|
|
6
|
+
src/apiverve_htmltotext/exceptions.py
|
|
7
|
+
src/apiverve_htmltotext/setup.py
|
|
8
|
+
src/apiverve_htmltotext/setup_dep.py
|
|
9
|
+
src/apiverve_htmltotext.egg-info/PKG-INFO
|
|
10
|
+
src/apiverve_htmltotext.egg-info/SOURCES.txt
|
|
11
|
+
src/apiverve_htmltotext.egg-info/dependency_links.txt
|
|
12
|
+
src/apiverve_htmltotext.egg-info/requires.txt
|
|
13
|
+
src/apiverve_htmltotext.egg-info/top_level.txt
|
|
14
|
+
src/apiverve_htmltotext/tests/__init__.py
|
|
15
|
+
src/apiverve_htmltotext/tests/test_api.py
|
|
16
|
+
tests/test_api.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.25.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
apiverve_htmltotext
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from apiverve_htmltotext.apiClient import HtmltotextAPIClient
|
|
3
|
+
from unittest.mock import patch
|
|
4
|
+
|
|
5
|
+
class TestHtmltotextAPIClient(unittest.TestCase):
|
|
6
|
+
|
|
7
|
+
def setUp(self):
|
|
8
|
+
self.api_key = 'test_api_key'
|
|
9
|
+
self.client = HtmltotextAPIClient(self.api_key)
|
|
10
|
+
|
|
11
|
+
@patch('apiverve_htmltotext.apiClient.requests.get')
|
|
12
|
+
def test_make_request_success(self, mock_get):
|
|
13
|
+
# Assuming there's an endpoint 'test_endpoint' for testing purposes
|
|
14
|
+
mock_get.return_value.status_code = 200
|
|
15
|
+
mock_get.return_value.json.return_value = {'test': 'test'}
|
|
16
|
+
response = self.client.get('test_endpoint')
|
|
17
|
+
self.assertIsInstance(response, dict)
|
|
18
|
+
|
|
19
|
+
@patch('apiverve_htmltotext.apiClient.requests.get')
|
|
20
|
+
def test_make_request_failure(self, mock_get):
|
|
21
|
+
# Assuming there's an endpoint 'test_endpoint' for testing purposes
|
|
22
|
+
mock_get.return_value.status_code = 404
|
|
23
|
+
with self.assertRaises(Exception):
|
|
24
|
+
self.client.get('test_endpoint')
|
|
25
|
+
|
|
26
|
+
if __name__ == '__main__':
|
|
27
|
+
unittest.main()
|