apiverve-base64encoderdecoder 1.2.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.
- apiverve_base64encoderdecoder/__init__.py +3 -0
- apiverve_base64encoderdecoder/apiClient.py +251 -0
- apiverve_base64encoderdecoder/exceptions.py +3 -0
- apiverve_base64encoderdecoder/setup.py +26 -0
- apiverve_base64encoderdecoder/setup_dep.py +21 -0
- apiverve_base64encoderdecoder/tests/__init__.py +1 -0
- apiverve_base64encoderdecoder/tests/test_api.py +19 -0
- apiverve_base64encoderdecoder-1.2.0.dist-info/METADATA +327 -0
- apiverve_base64encoderdecoder-1.2.0.dist-info/RECORD +12 -0
- apiverve_base64encoderdecoder-1.2.0.dist-info/WHEEL +5 -0
- apiverve_base64encoderdecoder-1.2.0.dist-info/licenses/LICENSE +21 -0
- apiverve_base64encoderdecoder-1.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from typing import Dict, Optional, Any, List
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
import requests
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Base64APIClientError(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(Base64APIClientError):
|
|
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 Base64APIClient:
|
|
25
|
+
# Validation rules for parameters (generated from schema)
|
|
26
|
+
VALIDATION_RULES = {
|
|
27
|
+
"text": {"type": "string", "required": True},
|
|
28
|
+
"action": {"type": "string", "required": False, "default": "encode"}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
# Format validation patterns
|
|
32
|
+
FORMAT_PATTERNS = {
|
|
33
|
+
'email': r'^[^\s@]+@[^\s@]+\.[^\s@]+$',
|
|
34
|
+
'url': r'^https?://.+',
|
|
35
|
+
'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}$',
|
|
36
|
+
'date': r'^\d{4}-\d{2}-\d{2}$',
|
|
37
|
+
'hexColor': r'^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
def __init__(self, api_key: str, secure: bool = True, debug: bool = False):
|
|
41
|
+
"""
|
|
42
|
+
Initialize the Base64APIClient with the API key and optional settings
|
|
43
|
+
|
|
44
|
+
:param api_key: Your APIVerve API key
|
|
45
|
+
:param secure: Deprecated. Always set to True
|
|
46
|
+
:param debug: Enable debug logging (default: False)
|
|
47
|
+
:raises Base64APIClientError: If API key is invalid
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
self._validate_api_key(api_key)
|
|
51
|
+
|
|
52
|
+
self.api_key = api_key
|
|
53
|
+
self.secure = secure
|
|
54
|
+
self.debug = debug
|
|
55
|
+
self.base_url = 'https://api.apiverve.com/v1/base64'
|
|
56
|
+
self.headers = {
|
|
57
|
+
'x-api-key': self.api_key,
|
|
58
|
+
'auth-mode': 'pypi-package'
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
# Create a session for connection pooling
|
|
62
|
+
self.session = requests.Session()
|
|
63
|
+
self.session.headers.update(self.headers)
|
|
64
|
+
|
|
65
|
+
def _validate_api_key(self, api_key: str) -> None:
|
|
66
|
+
"""
|
|
67
|
+
Validate the API key format
|
|
68
|
+
|
|
69
|
+
:param api_key: API key to validate
|
|
70
|
+
:raises Base64APIClientError: If API key is invalid
|
|
71
|
+
"""
|
|
72
|
+
if not api_key or not api_key.strip():
|
|
73
|
+
raise Base64APIClientError(
|
|
74
|
+
"API key is required. Get your API key at: https://apiverve.com"
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
# Check format (GUID, prefixed keys like apv_xxx, or alphanumeric)
|
|
78
|
+
if not re.match(r'^[a-zA-Z0-9_-]+$', api_key):
|
|
79
|
+
raise Base64APIClientError(
|
|
80
|
+
"Invalid API key format. API key should only contain letters, numbers, hyphens, and underscores. "
|
|
81
|
+
"Get your API key at: https://apiverve.com"
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
def _log(self, message: str) -> None:
|
|
85
|
+
"""
|
|
86
|
+
Log a debug message if debug mode is enabled
|
|
87
|
+
|
|
88
|
+
:param message: Message to log
|
|
89
|
+
"""
|
|
90
|
+
if self.debug:
|
|
91
|
+
print(f"[Base64APIClient DEBUG] {message}")
|
|
92
|
+
|
|
93
|
+
def _validate_params(self, params: Optional[Dict[str, Any]]) -> None:
|
|
94
|
+
"""
|
|
95
|
+
Validate parameters against schema rules
|
|
96
|
+
|
|
97
|
+
:param params: Parameters to validate
|
|
98
|
+
:raises ValidationError: If validation fails
|
|
99
|
+
"""
|
|
100
|
+
if not self.VALIDATION_RULES:
|
|
101
|
+
return
|
|
102
|
+
|
|
103
|
+
errors = []
|
|
104
|
+
params = params or {}
|
|
105
|
+
|
|
106
|
+
for param_name, rules in self.VALIDATION_RULES.items():
|
|
107
|
+
value = params.get(param_name)
|
|
108
|
+
|
|
109
|
+
# Check required
|
|
110
|
+
if rules.get('required') and (value is None or value == ''):
|
|
111
|
+
errors.append(f"Required parameter [{param_name}] is missing.")
|
|
112
|
+
continue
|
|
113
|
+
|
|
114
|
+
# Skip validation if value is not provided and not required
|
|
115
|
+
if value is None:
|
|
116
|
+
continue
|
|
117
|
+
|
|
118
|
+
param_type = rules.get('type', 'string')
|
|
119
|
+
|
|
120
|
+
# Type validation
|
|
121
|
+
if param_type in ('integer', 'number'):
|
|
122
|
+
try:
|
|
123
|
+
num_value = float(value) if param_type == 'number' else int(value)
|
|
124
|
+
|
|
125
|
+
# Min/max validation
|
|
126
|
+
if 'min' in rules and num_value < rules['min']:
|
|
127
|
+
errors.append(f"Parameter [{param_name}] must be at least {rules['min']}.")
|
|
128
|
+
if 'max' in rules and num_value > rules['max']:
|
|
129
|
+
errors.append(f"Parameter [{param_name}] must be at most {rules['max']}.")
|
|
130
|
+
except (ValueError, TypeError):
|
|
131
|
+
errors.append(f"Parameter [{param_name}] must be a valid {param_type}.")
|
|
132
|
+
continue
|
|
133
|
+
|
|
134
|
+
elif param_type == 'string':
|
|
135
|
+
if not isinstance(value, str):
|
|
136
|
+
errors.append(f"Parameter [{param_name}] must be a string.")
|
|
137
|
+
continue
|
|
138
|
+
|
|
139
|
+
# Length validation
|
|
140
|
+
if 'minLength' in rules and len(value) < rules['minLength']:
|
|
141
|
+
errors.append(f"Parameter [{param_name}] must be at least {rules['minLength']} characters.")
|
|
142
|
+
if 'maxLength' in rules and len(value) > rules['maxLength']:
|
|
143
|
+
errors.append(f"Parameter [{param_name}] must be at most {rules['maxLength']} characters.")
|
|
144
|
+
|
|
145
|
+
# Format validation
|
|
146
|
+
if 'format' in rules and rules['format'] in self.FORMAT_PATTERNS:
|
|
147
|
+
pattern = self.FORMAT_PATTERNS[rules['format']]
|
|
148
|
+
if not re.match(pattern, value, re.IGNORECASE):
|
|
149
|
+
errors.append(f"Parameter [{param_name}] must be a valid {rules['format']}.")
|
|
150
|
+
|
|
151
|
+
elif param_type == 'boolean':
|
|
152
|
+
if not isinstance(value, bool) and value not in ('true', 'false', True, False):
|
|
153
|
+
errors.append(f"Parameter [{param_name}] must be a boolean.")
|
|
154
|
+
|
|
155
|
+
elif param_type == 'array':
|
|
156
|
+
if not isinstance(value, list):
|
|
157
|
+
errors.append(f"Parameter [{param_name}] must be an array.")
|
|
158
|
+
|
|
159
|
+
# Enum validation
|
|
160
|
+
if 'enum' in rules and value not in rules['enum']:
|
|
161
|
+
errors.append(f"Parameter [{param_name}] must be one of: {', '.join(map(str, rules['enum']))}.")
|
|
162
|
+
|
|
163
|
+
if errors:
|
|
164
|
+
raise ValidationError(errors)
|
|
165
|
+
|
|
166
|
+
def execute(self, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]: # Returns Base64EncoderDecoderData in 'data' field
|
|
167
|
+
"""
|
|
168
|
+
Execute the API request
|
|
169
|
+
|
|
170
|
+
:param params: API parameters (optional)
|
|
171
|
+
:return: API response as a dictionary
|
|
172
|
+
:raises Base64APIClientError: If the request fails or returns an error
|
|
173
|
+
:raises ValidationError: If parameter validation fails
|
|
174
|
+
"""
|
|
175
|
+
|
|
176
|
+
# Validate parameters against schema rules
|
|
177
|
+
self._validate_params(params)
|
|
178
|
+
|
|
179
|
+
method = "GET"
|
|
180
|
+
|
|
181
|
+
self._log(f"Making {method} request to {self.base_url}")
|
|
182
|
+
if params:
|
|
183
|
+
self._log(f"Parameters: {params}")
|
|
184
|
+
|
|
185
|
+
try:
|
|
186
|
+
if method.upper() == 'POST':
|
|
187
|
+
self._log("Sending POST request with JSON body")
|
|
188
|
+
response = self.session.post(self.base_url, json=params, timeout=30)
|
|
189
|
+
else:
|
|
190
|
+
self._log("Sending GET request with query parameters")
|
|
191
|
+
response = self.session.get(self.base_url, params=params, timeout=30)
|
|
192
|
+
|
|
193
|
+
self._log(f"Response status code: {response.status_code}")
|
|
194
|
+
|
|
195
|
+
# Try to parse JSON response
|
|
196
|
+
try:
|
|
197
|
+
response_data = response.json()
|
|
198
|
+
except ValueError as e:
|
|
199
|
+
raise Base64APIClientError(
|
|
200
|
+
f"Invalid JSON response from API: {str(e)}",
|
|
201
|
+
status_code=response.status_code
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
# Check for API-level errors in the response
|
|
205
|
+
if response_data.get('status') == 'error':
|
|
206
|
+
error_message = response_data.get('error', 'Unknown API error')
|
|
207
|
+
self._log(f"API returned error: {error_message}")
|
|
208
|
+
raise Base64APIClientError(
|
|
209
|
+
error_message,
|
|
210
|
+
status_code=response.status_code,
|
|
211
|
+
response=response_data
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
# Check HTTP status code
|
|
215
|
+
if not response.ok:
|
|
216
|
+
error_message = response_data.get('error', f"HTTP {response.status_code} error")
|
|
217
|
+
self._log(f"HTTP error: {error_message}")
|
|
218
|
+
raise Base64APIClientError(
|
|
219
|
+
error_message,
|
|
220
|
+
status_code=response.status_code,
|
|
221
|
+
response=response_data
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
self._log("Request successful")
|
|
225
|
+
return response_data
|
|
226
|
+
|
|
227
|
+
except requests.exceptions.Timeout as e:
|
|
228
|
+
self._log(f"Request timeout: {str(e)}")
|
|
229
|
+
raise Base64APIClientError(f"Request timeout: {str(e)}")
|
|
230
|
+
except requests.exceptions.ConnectionError as e:
|
|
231
|
+
self._log(f"Connection error: {str(e)}")
|
|
232
|
+
raise Base64APIClientError(f"Connection error: {str(e)}")
|
|
233
|
+
except requests.exceptions.RequestException as e:
|
|
234
|
+
self._log(f"Request exception: {str(e)}")
|
|
235
|
+
raise Base64APIClientError(f"Request failed: {str(e)}")
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def close(self) -> None:
|
|
239
|
+
"""
|
|
240
|
+
Close the session and release resources
|
|
241
|
+
"""
|
|
242
|
+
self._log("Closing session")
|
|
243
|
+
self.session.close()
|
|
244
|
+
|
|
245
|
+
def __enter__(self):
|
|
246
|
+
"""Context manager entry"""
|
|
247
|
+
return self
|
|
248
|
+
|
|
249
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
250
|
+
"""Context manager exit"""
|
|
251
|
+
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_base64encoderdecoder',
|
|
13
|
+
version='1.2.0',
|
|
14
|
+
packages=find_packages(),
|
|
15
|
+
include_package_data=True,
|
|
16
|
+
install_requires=install_requires,
|
|
17
|
+
description='Base64 Encoder/Decoder is a simple tool for encoding and decoding Base64 strings. It supports both encoding text to Base64 and decoding Base64 back to text.',
|
|
18
|
+
author='APIVerve',
|
|
19
|
+
author_email='hello@apiverve.com',
|
|
20
|
+
url='https://apiverve.com/marketplace/base64?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_base64encoderdecoder',
|
|
5
|
+
version='1.2.0',
|
|
6
|
+
packages=find_packages(),
|
|
7
|
+
include_package_data=True,
|
|
8
|
+
install_requires=[
|
|
9
|
+
'requests',
|
|
10
|
+
'setuptools'
|
|
11
|
+
],
|
|
12
|
+
description='Base64 Encoder/Decoder is a simple tool for encoding and decoding Base64 strings. It supports both encoding text to Base64 and decoding Base64 back to text.',
|
|
13
|
+
author='APIVerve',
|
|
14
|
+
author_email='hello@apiverve.com',
|
|
15
|
+
url='https://apiverve.com/marketplace/base64?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_base64encoderdecoder.apiClient import Base64APIClient
|
|
3
|
+
|
|
4
|
+
class TestClient(unittest.TestCase):
|
|
5
|
+
|
|
6
|
+
def setUp(self):
|
|
7
|
+
self.api_key = 'test_api_key'
|
|
8
|
+
self.client = Base64APIClient(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,327 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: apiverve-base64encoderdecoder
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: Base64 Encoder/Decoder is a simple tool for encoding and decoding Base64 strings. It supports both encoding text to Base64 and decoding Base64 back to text.
|
|
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/base64-api
|
|
9
|
+
Project-URL: Documentation, https://docs.apiverve.com/api/base64?utm_source=pypi
|
|
10
|
+
Project-URL: Twitter, https://twitter.com/apivervehq
|
|
11
|
+
Keywords: base64,base64 encode,base64 decode,encoding,decoding
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
17
|
+
Classifier: Intended Audience :: Healthcare Industry
|
|
18
|
+
Classifier: Intended Audience :: Education
|
|
19
|
+
Classifier: Intended Audience :: Science/Research
|
|
20
|
+
Classifier: Intended Audience :: Information Technology
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Topic :: Utilities
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering
|
|
24
|
+
Classifier: Topic :: Education
|
|
25
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
|
|
26
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Site Management
|
|
27
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
28
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
29
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
30
|
+
Classifier: Topic :: Internet
|
|
31
|
+
Classifier: Topic :: Communications
|
|
32
|
+
Classifier: Topic :: Office/Business
|
|
33
|
+
Classifier: Topic :: Text Processing
|
|
34
|
+
Classifier: Topic :: Security
|
|
35
|
+
Classifier: Topic :: Database
|
|
36
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
37
|
+
Classifier: Topic :: Software Development :: Pre-processors
|
|
38
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
39
|
+
Classifier: Topic :: Software Development :: Testing
|
|
40
|
+
Classifier: Natural Language :: English
|
|
41
|
+
Requires-Python: >=3.9
|
|
42
|
+
Description-Content-Type: text/markdown
|
|
43
|
+
License-File: LICENSE
|
|
44
|
+
Requires-Dist: requests>=2.25.0
|
|
45
|
+
Dynamic: license-file
|
|
46
|
+
|
|
47
|
+
Base64 Encoder/Decoder API
|
|
48
|
+
============
|
|
49
|
+
|
|
50
|
+
Base64 Encoder/Decoder is a simple tool for encoding and decoding Base64 strings. It supports both encoding text to Base64 and decoding Base64 back to text.
|
|
51
|
+
|
|
52
|
+

|
|
53
|
+

|
|
54
|
+

|
|
55
|
+
|
|
56
|
+
This is a Python API Wrapper for the [Base64 Encoder/Decoder API](https://apiverve.com/marketplace/base64?utm_source=pypi&utm_medium=readme)
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
Using `pip`:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install apiverve-base64encoderdecoder
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Using `pip3`:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pip3 install apiverve-base64encoderdecoder
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Configuration
|
|
77
|
+
|
|
78
|
+
Before using the base64 API client, you have to setup your account and obtain your API Key.
|
|
79
|
+
You can get it by signing up at [https://apiverve.com](https://apiverve.com?utm_source=pypi&utm_medium=readme)
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Quick Start
|
|
84
|
+
|
|
85
|
+
Here's a simple example to get you started quickly:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from apiverve_base64encoderdecoder.apiClient import Base64APIClient
|
|
89
|
+
|
|
90
|
+
# Initialize the client with your APIVerve API key
|
|
91
|
+
api = Base64APIClient("[YOUR_API_KEY]")
|
|
92
|
+
|
|
93
|
+
query = {
|
|
94
|
+
"text": "Hello World",
|
|
95
|
+
"action": "encode"
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
try:
|
|
99
|
+
# Make the API call
|
|
100
|
+
result = api.execute(query)
|
|
101
|
+
|
|
102
|
+
# Print the result
|
|
103
|
+
print(result)
|
|
104
|
+
except Exception as e:
|
|
105
|
+
print(f"Error: {e}")
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Usage
|
|
111
|
+
|
|
112
|
+
The Base64 Encoder/Decoder API documentation is found here: [https://docs.apiverve.com/ref/base64](https://docs.apiverve.com/ref/base64?utm_source=pypi&utm_medium=readme).
|
|
113
|
+
You can find parameters, example responses, and status codes documented here.
|
|
114
|
+
|
|
115
|
+
### Setup
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
# Import the client module
|
|
119
|
+
from apiverve_base64encoderdecoder.apiClient import Base64APIClient
|
|
120
|
+
|
|
121
|
+
# Initialize the client with your APIVerve API key
|
|
122
|
+
api = Base64APIClient("[YOUR_API_KEY]")
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Perform Request
|
|
128
|
+
|
|
129
|
+
Using the API client, you can perform requests to the API.
|
|
130
|
+
|
|
131
|
+
###### Define Query
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
query = {
|
|
135
|
+
"text": "Hello World",
|
|
136
|
+
"action": "encode"
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
###### Simple Request
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
# Make a request to the API
|
|
144
|
+
result = api.execute(query)
|
|
145
|
+
|
|
146
|
+
# Print the result
|
|
147
|
+
print(result)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
###### Example Response
|
|
151
|
+
|
|
152
|
+
```json
|
|
153
|
+
{
|
|
154
|
+
"status": "ok",
|
|
155
|
+
"error": null,
|
|
156
|
+
"data": {
|
|
157
|
+
"action": "encode",
|
|
158
|
+
"original": "Hello World",
|
|
159
|
+
"encoded": "SGVsbG8gV29ybGQ=",
|
|
160
|
+
"length": 16
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Error Handling
|
|
168
|
+
|
|
169
|
+
The API client provides comprehensive error handling through the `Base64APIClientError` exception. Here are some examples:
|
|
170
|
+
|
|
171
|
+
### Basic Error Handling
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
from apiverve_base64encoderdecoder.apiClient import Base64APIClient, Base64APIClientError
|
|
175
|
+
|
|
176
|
+
api = Base64APIClient("[YOUR_API_KEY]")
|
|
177
|
+
|
|
178
|
+
query = {
|
|
179
|
+
"text": "Hello World",
|
|
180
|
+
"action": "encode"
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
try:
|
|
184
|
+
result = api.execute(query)
|
|
185
|
+
print("Success!")
|
|
186
|
+
print(result)
|
|
187
|
+
except Base64APIClientError as e:
|
|
188
|
+
print(f"API Error: {e.message}")
|
|
189
|
+
if e.status_code:
|
|
190
|
+
print(f"Status Code: {e.status_code}")
|
|
191
|
+
if e.response:
|
|
192
|
+
print(f"Response: {e.response}")
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Handling Specific Error Types
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
from apiverve_base64encoderdecoder.apiClient import Base64APIClient, Base64APIClientError
|
|
199
|
+
|
|
200
|
+
api = Base64APIClient("[YOUR_API_KEY]")
|
|
201
|
+
|
|
202
|
+
query = {
|
|
203
|
+
"text": "Hello World",
|
|
204
|
+
"action": "encode"
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
try:
|
|
208
|
+
result = api.execute(query)
|
|
209
|
+
|
|
210
|
+
# Check for successful response
|
|
211
|
+
if result.get('status') == 'success':
|
|
212
|
+
print("Request successful!")
|
|
213
|
+
print(result.get('data'))
|
|
214
|
+
else:
|
|
215
|
+
print(f"API returned an error: {result.get('error')}")
|
|
216
|
+
|
|
217
|
+
except Base64APIClientError as e:
|
|
218
|
+
# Handle API client errors
|
|
219
|
+
if e.status_code == 401:
|
|
220
|
+
print("Unauthorized: Invalid API key")
|
|
221
|
+
elif e.status_code == 429:
|
|
222
|
+
print("Rate limit exceeded")
|
|
223
|
+
elif e.status_code >= 500:
|
|
224
|
+
print("Server error - please try again later")
|
|
225
|
+
else:
|
|
226
|
+
print(f"API error: {e.message}")
|
|
227
|
+
except Exception as e:
|
|
228
|
+
# Handle unexpected errors
|
|
229
|
+
print(f"Unexpected error: {str(e)}")
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Using Context Manager (Recommended)
|
|
233
|
+
|
|
234
|
+
The client supports the context manager protocol for automatic resource cleanup:
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
from apiverve_base64encoderdecoder.apiClient import Base64APIClient, Base64APIClientError
|
|
238
|
+
|
|
239
|
+
query = {
|
|
240
|
+
"text": "Hello World",
|
|
241
|
+
"action": "encode"
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
# Using context manager ensures proper cleanup
|
|
245
|
+
with Base64APIClient("[YOUR_API_KEY]") as api:
|
|
246
|
+
try:
|
|
247
|
+
result = api.execute(query)
|
|
248
|
+
print(result)
|
|
249
|
+
except Base64APIClientError as e:
|
|
250
|
+
print(f"Error: {e.message}")
|
|
251
|
+
# Session is automatically closed here
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## Advanced Features
|
|
257
|
+
|
|
258
|
+
### Debug Mode
|
|
259
|
+
|
|
260
|
+
Enable debug logging to see detailed request and response information:
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
from apiverve_base64encoderdecoder.apiClient import Base64APIClient
|
|
264
|
+
|
|
265
|
+
# Enable debug mode
|
|
266
|
+
api = Base64APIClient("[YOUR_API_KEY]", debug=True)
|
|
267
|
+
|
|
268
|
+
query = {
|
|
269
|
+
"text": "Hello World",
|
|
270
|
+
"action": "encode"
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
# Debug information will be printed to console
|
|
274
|
+
result = api.execute(query)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Manual Session Management
|
|
278
|
+
|
|
279
|
+
If you need to manually manage the session lifecycle:
|
|
280
|
+
|
|
281
|
+
```python
|
|
282
|
+
from apiverve_base64encoderdecoder.apiClient import Base64APIClient
|
|
283
|
+
|
|
284
|
+
api = Base64APIClient("[YOUR_API_KEY]")
|
|
285
|
+
|
|
286
|
+
query = {
|
|
287
|
+
"text": "Hello World",
|
|
288
|
+
"action": "encode"
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
try:
|
|
292
|
+
result = api.execute(query)
|
|
293
|
+
print(result)
|
|
294
|
+
finally:
|
|
295
|
+
# Manually close the session when done
|
|
296
|
+
api.close()
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## Customer Support
|
|
302
|
+
|
|
303
|
+
Need any assistance? [Get in touch with Customer Support](https://apiverve.com/contact?utm_source=pypi&utm_medium=readme).
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## Updates
|
|
308
|
+
Stay up to date by following [@apiverveHQ](https://twitter.com/apiverveHQ) on Twitter.
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## Legal
|
|
313
|
+
|
|
314
|
+
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.
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
## License
|
|
319
|
+
Licensed under the The MIT License (MIT)
|
|
320
|
+
|
|
321
|
+
Copyright (©) 2026 APIVerve, and EvlarSoft LLC
|
|
322
|
+
|
|
323
|
+
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:
|
|
324
|
+
|
|
325
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
326
|
+
|
|
327
|
+
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,12 @@
|
|
|
1
|
+
apiverve_base64encoderdecoder/__init__.py,sha256=Bbjt9SyOFqy5pRaQBCHnXukuPVZCLYorsYMDqQcqJW8,115
|
|
2
|
+
apiverve_base64encoderdecoder/apiClient.py,sha256=V7pGvbgonWWETZsKhUW2u3A829CqHptTvI7Q87_6j6Q,9971
|
|
3
|
+
apiverve_base64encoderdecoder/exceptions.py,sha256=PppFloLH1sRRlEM6in5v620aNbO3g9CxAw5nuVbC86g,109
|
|
4
|
+
apiverve_base64encoderdecoder/setup.py,sha256=Lq5WK1U8u0-j8m-eAIrTOEai34nuXjjRO72BwXbpr0Y,1043
|
|
5
|
+
apiverve_base64encoderdecoder/setup_dep.py,sha256=Xmztj2nsHDZj-FpJdGRGoyFbfAlqLGV0MFH5AapOJwE,742
|
|
6
|
+
apiverve_base64encoderdecoder/tests/__init__.py,sha256=w6P0tAvlmu3OJbVjWR0J1p1bxOlrB2LqnMv2tigQCu4,26
|
|
7
|
+
apiverve_base64encoderdecoder/tests/test_api.py,sha256=SxPEpJ4hk3nCojd5onAUoZzJkvMNjKK7TUwiwLwZidI,616
|
|
8
|
+
apiverve_base64encoderdecoder-1.2.0.dist-info/licenses/LICENSE,sha256=YsfLd-GMs4-ZhMK0ecz-_Jr9DX9cPphkby5JVKaPgEY,1109
|
|
9
|
+
apiverve_base64encoderdecoder-1.2.0.dist-info/METADATA,sha256=AcUUs7nOJVyPSA_9HZMYAyrCUbQZdS9wNalF55vXayg,9478
|
|
10
|
+
apiverve_base64encoderdecoder-1.2.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
11
|
+
apiverve_base64encoderdecoder-1.2.0.dist-info/top_level.txt,sha256=KJxblPibluB-CxSjwGZOB-_E40rHXB_oyerL7Tqz2tg,30
|
|
12
|
+
apiverve_base64encoderdecoder-1.2.0.dist-info/RECORD,,
|
|
@@ -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 @@
|
|
|
1
|
+
apiverve_base64encoderdecoder
|