ipc-artsnoa 0.1.0__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.
- ipc_artsnoa-0.1.0/.gitignore +5 -0
- ipc_artsnoa-0.1.0/PKG-INFO +303 -0
- ipc_artsnoa-0.1.0/README.md +279 -0
- ipc_artsnoa-0.1.0/ipc_artsnoa/__init__.py +17 -0
- ipc_artsnoa-0.1.0/ipc_artsnoa/client.py +94 -0
- ipc_artsnoa-0.1.0/ipc_artsnoa/exceptions.py +20 -0
- ipc_artsnoa-0.1.0/ipc_artsnoa/modules/__init__.py +7 -0
- ipc_artsnoa-0.1.0/ipc_artsnoa/modules/_request_handler.py +50 -0
- ipc_artsnoa-0.1.0/ipc_artsnoa/modules/get_ip.py +31 -0
- ipc_artsnoa-0.1.0/ipc_artsnoa/modules/get_ip_details.py +31 -0
- ipc_artsnoa-0.1.0/ipc_artsnoa/modules/get_sdk_versions.py +31 -0
- ipc_artsnoa-0.1.0/pyproject.toml +44 -0
- ipc_artsnoa-0.1.0/uv.lock +427 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ipc-artsnoa
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for ipc.artsnoa.com API - IP geolocation and information service
|
|
5
|
+
Project-URL: Homepage, https://ipc.artsnoa.com
|
|
6
|
+
Project-URL: Documentation, https://github.com/artsnoa/ipc-python-sdk
|
|
7
|
+
Project-URL: Repository, https://github.com/artsnoa/ipc-python-sdk
|
|
8
|
+
Project-URL: Issues, https://github.com/artsnoa/ipc-python-sdk/issues
|
|
9
|
+
Author-email: artsnoa <support@artsnoa.com>
|
|
10
|
+
Keywords: api,artsnoa,geolocation,ip,ipc,sdk
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Internet
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: requests>=2.31.0
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# IPC Artsnoa Python SDK
|
|
26
|
+
|
|
27
|
+
Official Python SDK for [ipc.artsnoa.com](https://ipc.artsnoa.com) API - Get your IP address and location information.
|
|
28
|
+
|
|
29
|
+
## Features
|
|
30
|
+
|
|
31
|
+
- Simple and intuitive API
|
|
32
|
+
- Type hints for better IDE support
|
|
33
|
+
- Comprehensive error handling
|
|
34
|
+
- Context manager support
|
|
35
|
+
- Minimal dependencies
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install ipc-artsnoa
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or with uv:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
uv add ipc-artsnoa
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quick Start
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from ipc_artsnoa import IPCClient
|
|
53
|
+
|
|
54
|
+
# Initialize client (API key is optional)
|
|
55
|
+
client = IPCClient(api_key='YOUR_API_KEY')
|
|
56
|
+
|
|
57
|
+
# Get basic IP information
|
|
58
|
+
data = client.get_ip()
|
|
59
|
+
print(f'Your IP: {data["ip"]}, Country: {data["country"]}')
|
|
60
|
+
|
|
61
|
+
# Get detailed IP information
|
|
62
|
+
details = client.get_ip_details()
|
|
63
|
+
print(f'IP: {details["ip"]}, ASN: {details["asn"]}, Currency: {details["currency"]}')
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Usage Examples
|
|
67
|
+
|
|
68
|
+
### Basic Usage
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from ipc_artsnoa import IPCClient
|
|
72
|
+
|
|
73
|
+
# Create client with API key
|
|
74
|
+
client = IPCClient(api_key='YOUR_API_KEY')
|
|
75
|
+
|
|
76
|
+
# Get basic IP information
|
|
77
|
+
data = client.get_ip()
|
|
78
|
+
print(f"IP: {data['ip']}")
|
|
79
|
+
print(f"Country: {data['country']}")
|
|
80
|
+
|
|
81
|
+
# Without API key
|
|
82
|
+
client = IPCClient()
|
|
83
|
+
data = client.get_ip()
|
|
84
|
+
print(f"Your IP: {data['ip']}")
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Detailed IP Information
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from ipc_artsnoa import IPCClient
|
|
91
|
+
|
|
92
|
+
client = IPCClient(api_key='YOUR_API_KEY')
|
|
93
|
+
|
|
94
|
+
# Get detailed information including ASN, currency, languages
|
|
95
|
+
details = client.get_ip_details()
|
|
96
|
+
print(f"IP: {details['ip']}")
|
|
97
|
+
print(f"User Agent: {details['userAgent']}")
|
|
98
|
+
print(f"ASN: {details['asn']}")
|
|
99
|
+
print(f"Country: {details['country']}")
|
|
100
|
+
print(f"Currency: {details['currency']}")
|
|
101
|
+
print(f"Languages: {details['languages']}")
|
|
102
|
+
print(f"Timestamp: {details['timestamp']}")
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### SDK Version Information
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from ipc_artsnoa import IPCClient
|
|
109
|
+
|
|
110
|
+
client = IPCClient()
|
|
111
|
+
|
|
112
|
+
# Get available SDK versions
|
|
113
|
+
versions = client.get_sdk_versions()
|
|
114
|
+
print(f"Python SDK: {versions['python']}")
|
|
115
|
+
print(f"JavaScript SDK: {versions['javascript']}")
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Custom Configuration
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from ipc_artsnoa import IPCClient
|
|
122
|
+
|
|
123
|
+
# Custom timeout
|
|
124
|
+
client = IPCClient(
|
|
125
|
+
api_key='YOUR_API_KEY',
|
|
126
|
+
timeout=15.0
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
data = client.get_ip()
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Using Context Manager
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from ipc_artsnoa import IPCClient
|
|
136
|
+
|
|
137
|
+
# Automatically closes session when done
|
|
138
|
+
with IPCClient(api_key='YOUR_API_KEY') as client:
|
|
139
|
+
data = client.get_ip()
|
|
140
|
+
print(f"IP: {data['ip']}")
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Error Handling
|
|
144
|
+
|
|
145
|
+
The SDK provides specific exception types for different error scenarios:
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from ipc_artsnoa import (
|
|
149
|
+
IPCClient,
|
|
150
|
+
IPCError,
|
|
151
|
+
IPCAPIError,
|
|
152
|
+
IPCConnectionError,
|
|
153
|
+
IPCTimeoutError
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
client = IPCClient(api_key='YOUR_API_KEY')
|
|
157
|
+
|
|
158
|
+
try:
|
|
159
|
+
data = client.get_ip()
|
|
160
|
+
print(f"Your IP: {data['ip']}")
|
|
161
|
+
except IPCAPIError as e:
|
|
162
|
+
print(f"API error: {e}")
|
|
163
|
+
if hasattr(e, 'status_code'):
|
|
164
|
+
print(f"Status code: {e.status_code}")
|
|
165
|
+
except IPCConnectionError as e:
|
|
166
|
+
print(f"Connection error: {e}")
|
|
167
|
+
except IPCTimeoutError as e:
|
|
168
|
+
print(f"Request timeout: {e}")
|
|
169
|
+
except IPCError as e:
|
|
170
|
+
print(f"IPC error: {e}")
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## API Reference
|
|
174
|
+
|
|
175
|
+
### IPCClient
|
|
176
|
+
|
|
177
|
+
#### Constructor
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
IPCClient(
|
|
181
|
+
api_key: str | None = None,
|
|
182
|
+
timeout: float = 10.0
|
|
183
|
+
)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Parameters:**
|
|
187
|
+
- `api_key` (str | None): API key for authentication. Optional.
|
|
188
|
+
- `timeout` (float): Request timeout in seconds. Defaults to 10.0
|
|
189
|
+
|
|
190
|
+
#### Methods
|
|
191
|
+
|
|
192
|
+
##### `get_ip() -> dict`
|
|
193
|
+
|
|
194
|
+
Get basic IP address and location information.
|
|
195
|
+
|
|
196
|
+
**Returns:**
|
|
197
|
+
- Dictionary containing basic IP information including:
|
|
198
|
+
- `ip`: Your IP address
|
|
199
|
+
- `country`: Country code
|
|
200
|
+
|
|
201
|
+
**Raises:**
|
|
202
|
+
- `IPCAPIError`: When API returns an error response
|
|
203
|
+
- `IPCConnectionError`: When connection fails
|
|
204
|
+
- `IPCTimeoutError`: When request times out
|
|
205
|
+
|
|
206
|
+
**Example:**
|
|
207
|
+
```python
|
|
208
|
+
data = client.get_ip()
|
|
209
|
+
print(f"IP: {data['ip']}, Country: {data['country']}")
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
##### `get_ip_details() -> dict`
|
|
213
|
+
|
|
214
|
+
Get detailed IP address information.
|
|
215
|
+
|
|
216
|
+
**Returns:**
|
|
217
|
+
- Dictionary containing detailed IP information including:
|
|
218
|
+
- `ip`: Your IP address
|
|
219
|
+
- `userAgent`: Browser user agent string
|
|
220
|
+
- `asn`: Autonomous System Number
|
|
221
|
+
- `country`: Country code
|
|
222
|
+
- `currency`: Country currency code
|
|
223
|
+
- `languages`: Supported languages
|
|
224
|
+
- `timestamp`: Request timestamp
|
|
225
|
+
- `version`: API version
|
|
226
|
+
|
|
227
|
+
**Raises:**
|
|
228
|
+
- `IPCAPIError`: When API returns an error response
|
|
229
|
+
- `IPCConnectionError`: When connection fails
|
|
230
|
+
- `IPCTimeoutError`: When request times out
|
|
231
|
+
|
|
232
|
+
**Example:**
|
|
233
|
+
```python
|
|
234
|
+
details = client.get_ip_details()
|
|
235
|
+
print(f"IP: {details['ip']}, ASN: {details['asn']}")
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
##### `get_sdk_versions() -> dict`
|
|
239
|
+
|
|
240
|
+
Get available SDK versions.
|
|
241
|
+
|
|
242
|
+
**Returns:**
|
|
243
|
+
- Dictionary containing SDK versions for different platforms:
|
|
244
|
+
- `python`: Python SDK version
|
|
245
|
+
- `javascript`: JavaScript SDK version
|
|
246
|
+
|
|
247
|
+
**Raises:**
|
|
248
|
+
- `IPCAPIError`: When API returns an error response
|
|
249
|
+
- `IPCConnectionError`: When connection fails
|
|
250
|
+
- `IPCTimeoutError`: When request times out
|
|
251
|
+
|
|
252
|
+
**Example:**
|
|
253
|
+
```python
|
|
254
|
+
versions = client.get_sdk_versions()
|
|
255
|
+
print(f"Python SDK: {versions['python']}")
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
##### `close()`
|
|
259
|
+
|
|
260
|
+
Close the underlying HTTP session.
|
|
261
|
+
|
|
262
|
+
**Example:**
|
|
263
|
+
```python
|
|
264
|
+
client.close()
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
#### Context Manager Support
|
|
268
|
+
|
|
269
|
+
The client supports context manager protocol for automatic resource cleanup:
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
with IPCClient(api_key='YOUR_API_KEY') as client:
|
|
273
|
+
data = client.get_ip()
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## Development
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
# Clone repository
|
|
280
|
+
git clone https://github.com/artsnoa/ipc-python-sdk.git
|
|
281
|
+
cd ipc-python-sdk
|
|
282
|
+
|
|
283
|
+
# Install dependencies with uv
|
|
284
|
+
uv sync
|
|
285
|
+
|
|
286
|
+
# Build package
|
|
287
|
+
uv build
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## Requirements
|
|
291
|
+
|
|
292
|
+
- Python 3.10 or higher
|
|
293
|
+
- requests >= 2.31.0
|
|
294
|
+
|
|
295
|
+
## License
|
|
296
|
+
|
|
297
|
+
MIT License
|
|
298
|
+
|
|
299
|
+
## Support
|
|
300
|
+
|
|
301
|
+
- Documentation: [https://github.com/artsnoa/ipc-python-sdk](https://github.com/artsnoa/ipc-python-sdk)
|
|
302
|
+
- Issues: [https://github.com/artsnoa/ipc-python-sdk/issues](https://github.com/artsnoa/ipc-python-sdk/issues)
|
|
303
|
+
- Email: aurora@artsnoa.com
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
# IPC Artsnoa Python SDK
|
|
2
|
+
|
|
3
|
+
Official Python SDK for [ipc.artsnoa.com](https://ipc.artsnoa.com) API - Get your IP address and location information.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Simple and intuitive API
|
|
8
|
+
- Type hints for better IDE support
|
|
9
|
+
- Comprehensive error handling
|
|
10
|
+
- Context manager support
|
|
11
|
+
- Minimal dependencies
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install ipc-artsnoa
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or with uv:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
uv add ipc-artsnoa
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from ipc_artsnoa import IPCClient
|
|
29
|
+
|
|
30
|
+
# Initialize client (API key is optional)
|
|
31
|
+
client = IPCClient(api_key='YOUR_API_KEY')
|
|
32
|
+
|
|
33
|
+
# Get basic IP information
|
|
34
|
+
data = client.get_ip()
|
|
35
|
+
print(f'Your IP: {data["ip"]}, Country: {data["country"]}')
|
|
36
|
+
|
|
37
|
+
# Get detailed IP information
|
|
38
|
+
details = client.get_ip_details()
|
|
39
|
+
print(f'IP: {details["ip"]}, ASN: {details["asn"]}, Currency: {details["currency"]}')
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage Examples
|
|
43
|
+
|
|
44
|
+
### Basic Usage
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from ipc_artsnoa import IPCClient
|
|
48
|
+
|
|
49
|
+
# Create client with API key
|
|
50
|
+
client = IPCClient(api_key='YOUR_API_KEY')
|
|
51
|
+
|
|
52
|
+
# Get basic IP information
|
|
53
|
+
data = client.get_ip()
|
|
54
|
+
print(f"IP: {data['ip']}")
|
|
55
|
+
print(f"Country: {data['country']}")
|
|
56
|
+
|
|
57
|
+
# Without API key
|
|
58
|
+
client = IPCClient()
|
|
59
|
+
data = client.get_ip()
|
|
60
|
+
print(f"Your IP: {data['ip']}")
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Detailed IP Information
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from ipc_artsnoa import IPCClient
|
|
67
|
+
|
|
68
|
+
client = IPCClient(api_key='YOUR_API_KEY')
|
|
69
|
+
|
|
70
|
+
# Get detailed information including ASN, currency, languages
|
|
71
|
+
details = client.get_ip_details()
|
|
72
|
+
print(f"IP: {details['ip']}")
|
|
73
|
+
print(f"User Agent: {details['userAgent']}")
|
|
74
|
+
print(f"ASN: {details['asn']}")
|
|
75
|
+
print(f"Country: {details['country']}")
|
|
76
|
+
print(f"Currency: {details['currency']}")
|
|
77
|
+
print(f"Languages: {details['languages']}")
|
|
78
|
+
print(f"Timestamp: {details['timestamp']}")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### SDK Version Information
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
from ipc_artsnoa import IPCClient
|
|
85
|
+
|
|
86
|
+
client = IPCClient()
|
|
87
|
+
|
|
88
|
+
# Get available SDK versions
|
|
89
|
+
versions = client.get_sdk_versions()
|
|
90
|
+
print(f"Python SDK: {versions['python']}")
|
|
91
|
+
print(f"JavaScript SDK: {versions['javascript']}")
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Custom Configuration
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from ipc_artsnoa import IPCClient
|
|
98
|
+
|
|
99
|
+
# Custom timeout
|
|
100
|
+
client = IPCClient(
|
|
101
|
+
api_key='YOUR_API_KEY',
|
|
102
|
+
timeout=15.0
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
data = client.get_ip()
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Using Context Manager
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from ipc_artsnoa import IPCClient
|
|
112
|
+
|
|
113
|
+
# Automatically closes session when done
|
|
114
|
+
with IPCClient(api_key='YOUR_API_KEY') as client:
|
|
115
|
+
data = client.get_ip()
|
|
116
|
+
print(f"IP: {data['ip']}")
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Error Handling
|
|
120
|
+
|
|
121
|
+
The SDK provides specific exception types for different error scenarios:
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from ipc_artsnoa import (
|
|
125
|
+
IPCClient,
|
|
126
|
+
IPCError,
|
|
127
|
+
IPCAPIError,
|
|
128
|
+
IPCConnectionError,
|
|
129
|
+
IPCTimeoutError
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
client = IPCClient(api_key='YOUR_API_KEY')
|
|
133
|
+
|
|
134
|
+
try:
|
|
135
|
+
data = client.get_ip()
|
|
136
|
+
print(f"Your IP: {data['ip']}")
|
|
137
|
+
except IPCAPIError as e:
|
|
138
|
+
print(f"API error: {e}")
|
|
139
|
+
if hasattr(e, 'status_code'):
|
|
140
|
+
print(f"Status code: {e.status_code}")
|
|
141
|
+
except IPCConnectionError as e:
|
|
142
|
+
print(f"Connection error: {e}")
|
|
143
|
+
except IPCTimeoutError as e:
|
|
144
|
+
print(f"Request timeout: {e}")
|
|
145
|
+
except IPCError as e:
|
|
146
|
+
print(f"IPC error: {e}")
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## API Reference
|
|
150
|
+
|
|
151
|
+
### IPCClient
|
|
152
|
+
|
|
153
|
+
#### Constructor
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
IPCClient(
|
|
157
|
+
api_key: str | None = None,
|
|
158
|
+
timeout: float = 10.0
|
|
159
|
+
)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Parameters:**
|
|
163
|
+
- `api_key` (str | None): API key for authentication. Optional.
|
|
164
|
+
- `timeout` (float): Request timeout in seconds. Defaults to 10.0
|
|
165
|
+
|
|
166
|
+
#### Methods
|
|
167
|
+
|
|
168
|
+
##### `get_ip() -> dict`
|
|
169
|
+
|
|
170
|
+
Get basic IP address and location information.
|
|
171
|
+
|
|
172
|
+
**Returns:**
|
|
173
|
+
- Dictionary containing basic IP information including:
|
|
174
|
+
- `ip`: Your IP address
|
|
175
|
+
- `country`: Country code
|
|
176
|
+
|
|
177
|
+
**Raises:**
|
|
178
|
+
- `IPCAPIError`: When API returns an error response
|
|
179
|
+
- `IPCConnectionError`: When connection fails
|
|
180
|
+
- `IPCTimeoutError`: When request times out
|
|
181
|
+
|
|
182
|
+
**Example:**
|
|
183
|
+
```python
|
|
184
|
+
data = client.get_ip()
|
|
185
|
+
print(f"IP: {data['ip']}, Country: {data['country']}")
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
##### `get_ip_details() -> dict`
|
|
189
|
+
|
|
190
|
+
Get detailed IP address information.
|
|
191
|
+
|
|
192
|
+
**Returns:**
|
|
193
|
+
- Dictionary containing detailed IP information including:
|
|
194
|
+
- `ip`: Your IP address
|
|
195
|
+
- `userAgent`: Browser user agent string
|
|
196
|
+
- `asn`: Autonomous System Number
|
|
197
|
+
- `country`: Country code
|
|
198
|
+
- `currency`: Country currency code
|
|
199
|
+
- `languages`: Supported languages
|
|
200
|
+
- `timestamp`: Request timestamp
|
|
201
|
+
- `version`: API version
|
|
202
|
+
|
|
203
|
+
**Raises:**
|
|
204
|
+
- `IPCAPIError`: When API returns an error response
|
|
205
|
+
- `IPCConnectionError`: When connection fails
|
|
206
|
+
- `IPCTimeoutError`: When request times out
|
|
207
|
+
|
|
208
|
+
**Example:**
|
|
209
|
+
```python
|
|
210
|
+
details = client.get_ip_details()
|
|
211
|
+
print(f"IP: {details['ip']}, ASN: {details['asn']}")
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
##### `get_sdk_versions() -> dict`
|
|
215
|
+
|
|
216
|
+
Get available SDK versions.
|
|
217
|
+
|
|
218
|
+
**Returns:**
|
|
219
|
+
- Dictionary containing SDK versions for different platforms:
|
|
220
|
+
- `python`: Python SDK version
|
|
221
|
+
- `javascript`: JavaScript SDK version
|
|
222
|
+
|
|
223
|
+
**Raises:**
|
|
224
|
+
- `IPCAPIError`: When API returns an error response
|
|
225
|
+
- `IPCConnectionError`: When connection fails
|
|
226
|
+
- `IPCTimeoutError`: When request times out
|
|
227
|
+
|
|
228
|
+
**Example:**
|
|
229
|
+
```python
|
|
230
|
+
versions = client.get_sdk_versions()
|
|
231
|
+
print(f"Python SDK: {versions['python']}")
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
##### `close()`
|
|
235
|
+
|
|
236
|
+
Close the underlying HTTP session.
|
|
237
|
+
|
|
238
|
+
**Example:**
|
|
239
|
+
```python
|
|
240
|
+
client.close()
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
#### Context Manager Support
|
|
244
|
+
|
|
245
|
+
The client supports context manager protocol for automatic resource cleanup:
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
with IPCClient(api_key='YOUR_API_KEY') as client:
|
|
249
|
+
data = client.get_ip()
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Development
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
# Clone repository
|
|
256
|
+
git clone https://github.com/artsnoa/ipc-python-sdk.git
|
|
257
|
+
cd ipc-python-sdk
|
|
258
|
+
|
|
259
|
+
# Install dependencies with uv
|
|
260
|
+
uv sync
|
|
261
|
+
|
|
262
|
+
# Build package
|
|
263
|
+
uv build
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Requirements
|
|
267
|
+
|
|
268
|
+
- Python 3.10 or higher
|
|
269
|
+
- requests >= 2.31.0
|
|
270
|
+
|
|
271
|
+
## License
|
|
272
|
+
|
|
273
|
+
MIT License
|
|
274
|
+
|
|
275
|
+
## Support
|
|
276
|
+
|
|
277
|
+
- Documentation: [https://github.com/artsnoa/ipc-python-sdk](https://github.com/artsnoa/ipc-python-sdk)
|
|
278
|
+
- Issues: [https://github.com/artsnoa/ipc-python-sdk/issues](https://github.com/artsnoa/ipc-python-sdk/issues)
|
|
279
|
+
- Email: aurora@artsnoa.com
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from .client import IPCClient
|
|
2
|
+
from .exceptions import (
|
|
3
|
+
IPCError,
|
|
4
|
+
IPCAPIError,
|
|
5
|
+
IPCConnectionError,
|
|
6
|
+
IPCTimeoutError,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
__version__ = "1.0.0"
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"IPCClient",
|
|
13
|
+
"IPCError",
|
|
14
|
+
"IPCAPIError",
|
|
15
|
+
"IPCConnectionError",
|
|
16
|
+
"IPCTimeoutError",
|
|
17
|
+
]
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
import requests
|
|
3
|
+
|
|
4
|
+
from . import modules
|
|
5
|
+
from .exceptions import IPCConnectionError, IPCTimeoutError, IPCAPIError
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class IPCClient:
|
|
9
|
+
"""Client for IPC API"""
|
|
10
|
+
|
|
11
|
+
DEFAULT_BASE_URL = "https://ipc.artsnoa.com"
|
|
12
|
+
BACKUP_BASE_URL = "https://ipc.makedns.net"
|
|
13
|
+
DEFAULT_TIMEOUT = 10.0
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
api_key: str | None = None,
|
|
18
|
+
timeout: float = DEFAULT_TIMEOUT
|
|
19
|
+
):
|
|
20
|
+
"""
|
|
21
|
+
Initialize IPC client
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
api_key: Optional API key for authentication
|
|
25
|
+
timeout: Request timeout in seconds (default: 10.0)
|
|
26
|
+
"""
|
|
27
|
+
self.api_key = api_key
|
|
28
|
+
self.base_url = self.DEFAULT_BASE_URL
|
|
29
|
+
self.timeout = timeout
|
|
30
|
+
self._session = requests.Session()
|
|
31
|
+
|
|
32
|
+
if self.api_key:
|
|
33
|
+
self._session.headers['Authorization'] = f'Bearer {self.api_key}'
|
|
34
|
+
|
|
35
|
+
def get_ip(self) -> dict[str, Any]:
|
|
36
|
+
"""
|
|
37
|
+
Get current IP information
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
dict containing IP information (ip, country, etc.)
|
|
41
|
+
|
|
42
|
+
Raises:
|
|
43
|
+
IPCAPIError: When API returns an error response
|
|
44
|
+
IPCConnectionError: When connection fails
|
|
45
|
+
IPCTimeoutError: When request times out
|
|
46
|
+
"""
|
|
47
|
+
try:
|
|
48
|
+
return modules.get_ip(self._session, self.base_url, self.timeout)
|
|
49
|
+
except (IPCConnectionError, IPCTimeoutError, IPCAPIError):
|
|
50
|
+
return modules.get_ip(self._session, self.BACKUP_BASE_URL, self.timeout)
|
|
51
|
+
|
|
52
|
+
def get_ip_details(self) -> dict[str, Any]:
|
|
53
|
+
"""
|
|
54
|
+
Get detailed IP information
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
dict containing detailed IP information (ip, userAgent, asn, country, currency, languages, timestamp, version)
|
|
58
|
+
|
|
59
|
+
Raises:
|
|
60
|
+
IPCAPIError: When API returns an error response
|
|
61
|
+
IPCConnectionError: When connection fails
|
|
62
|
+
IPCTimeoutError: When request times out
|
|
63
|
+
"""
|
|
64
|
+
try:
|
|
65
|
+
return modules.get_ip_details(self._session, self.base_url, self.timeout)
|
|
66
|
+
except (IPCConnectionError, IPCTimeoutError, IPCAPIError):
|
|
67
|
+
return modules.get_ip_details(self._session, self.BACKUP_BASE_URL, self.timeout)
|
|
68
|
+
|
|
69
|
+
def get_sdk_versions(self) -> dict[str, Any]:
|
|
70
|
+
"""
|
|
71
|
+
Get SDK versions
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
dict containing SDK versions (javascript, python, etc.)
|
|
75
|
+
|
|
76
|
+
Raises:
|
|
77
|
+
IPCAPIError: When API returns an error response
|
|
78
|
+
IPCConnectionError: When connection fails
|
|
79
|
+
IPCTimeoutError: When request times out
|
|
80
|
+
"""
|
|
81
|
+
try:
|
|
82
|
+
return modules.get_sdk_versions(self._session, self.base_url, self.timeout)
|
|
83
|
+
except (IPCConnectionError, IPCTimeoutError, IPCAPIError):
|
|
84
|
+
return modules.get_sdk_versions(self._session, self.BACKUP_BASE_URL, self.timeout)
|
|
85
|
+
|
|
86
|
+
def __enter__(self):
|
|
87
|
+
return self
|
|
88
|
+
|
|
89
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
90
|
+
self.close()
|
|
91
|
+
|
|
92
|
+
def close(self):
|
|
93
|
+
"""Close the session"""
|
|
94
|
+
self._session.close()
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class IPCError(Exception):
|
|
2
|
+
"""Base exception for IPC SDK"""
|
|
3
|
+
pass
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class IPCAPIError(IPCError):
|
|
7
|
+
"""Raised when API returns an error response"""
|
|
8
|
+
def __init__(self, message: str, status_code: int | None = None):
|
|
9
|
+
self.status_code = status_code
|
|
10
|
+
super().__init__(message)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class IPCConnectionError(IPCError):
|
|
14
|
+
"""Raised when connection to API fails"""
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class IPCTimeoutError(IPCError):
|
|
19
|
+
"""Raised when request times out"""
|
|
20
|
+
pass
|