smspva-sdk 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SMSPVA
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,3 @@
1
+ include METHODS.md
2
+ include LICENSE
3
+ prune tests
@@ -0,0 +1,82 @@
1
+ # SDK method index
2
+
3
+ All six packages cover these same 61 methods. Both Python clients use the Python names. PHP and Java use the JavaScript camelCase method names, with their own resource access syntax. Go capitalizes the first letter (for example, `GetBalance`); C# also appends `Async` (`GetBalanceAsync`). See each package README for request types and working usage. Parameters retain their API spelling.
4
+
5
+ ## activation
6
+
7
+ | Python (sync and async) | JavaScript / TypeScript | HTTP |
8
+ | --- | --- | --- |
9
+ | `client.activation.get_balance` | `client.activation.getBalance` | `GET /activation/balance` |
10
+ | `client.activation.get_user_info` | `client.activation.getUserInfo` | `GET /activation/userinfo` |
11
+ | `client.activation.get_operators` | `client.activation.getOperators` | `GET /activation/operators/{country}` |
12
+ | `client.activation.get_conversions` | `client.activation.getConversions` | `GET /activation/conversions/{service}` |
13
+ | `client.activation.get_message_type_settings` | `client.activation.getMessageTypeSettings` | `GET /activation/countryservicesettings` |
14
+ | `client.activation.get_all_number_counts` | `client.activation.getAllNumberCounts` | `GET /activation/countnumbers` |
15
+ | `client.activation.get_country_number_counts` | `client.activation.getCountryNumberCounts` | `GET /activation/countnumbers/{country}` |
16
+ | `client.activation.get_all_number_counts_compact` | `client.activation.getAllNumberCountsCompact` | `GET /activation/countnumberscompact` |
17
+ | `client.activation.get_country_number_counts_compact` | `client.activation.getCountryNumberCountsCompact` | `GET /activation/countnumberscompact/{country}` |
18
+ | `client.activation.get_service_price` | `client.activation.getServicePrice` | `GET /activation/serviceprice/{country}/{service}` |
19
+ | `client.activation.get_country_operator_prices` | `client.activation.getCountryOperatorPrices` | `GET /activation/serviceprice/{country}` |
20
+ | `client.activation.get_service_prices` | `client.activation.getServicePrices` | `GET /activation/serviceprices/{service}` |
21
+ | `client.activation.get_all_service_prices` | `client.activation.getAllServicePrices` | `GET /activation/servicesprices` |
22
+ | `client.activation.get_number` | `client.activation.getNumber` | `GET /activation/number/{country}/{service}` |
23
+ | `client.activation.get_number_by_operator` | `client.activation.getNumberByOperator` | `GET /activation/number/{country}/{service}/{operator}` |
24
+ | `client.activation.repeat_number` | `client.activation.repeatNumber` | `POST /activation/repeatnumber/{number}/{service}` |
25
+ | `client.activation.get_phone_status` | `client.activation.getPhoneStatus` | `GET /activation/statusphone/{orderid}` |
26
+ | `client.activation.start_sms` | `client.activation.startSms` | `PUT /activation/startsms/{orderid}` |
27
+ | `client.activation.receive_sms` | `client.activation.receiveSms` | `GET /activation/sms/{orderid}` |
28
+ | `client.activation.get_orders` | `client.activation.getOrders` | `GET /activation/orders` |
29
+ | `client.activation.get_number_status` | `client.activation.getNumberStatus` | `GET /activation/numberstatus/{number}/{service}` |
30
+ | `client.activation.clear_sms` | `client.activation.clearSms` | `PUT /activation/clearsms/{orderid}` |
31
+ | `client.activation.stop_sms` | `client.activation.stopSms` | `PUT /activation/stopsms/{orderid}` |
32
+ | `client.activation.cancel_order` | `client.activation.cancelOrder` | `PUT /activation/cancelorder/{orderid}` |
33
+ | `client.activation.block_number` | `client.activation.blockNumber` | `PUT /activation/blocknumber/{orderid}` |
34
+
35
+ ## rental
36
+
37
+ | Python (sync and async) | JavaScript / TypeScript | HTTP |
38
+ | --- | --- | --- |
39
+ | `client.rental.get_countries` | `client.rental.getCountries` | `GET /api/rent.php?method=getcountries` |
40
+ | `client.rental.get_default_services` | `client.rental.getDefaultServices` | `GET /api/rent.php?method=get_default_services` |
41
+ | `client.rental.get_countries_by_service` | `client.rental.getCountriesByService` | `GET /api/rent.php?method=get_country_by_service` |
42
+ | `client.rental.get_data` | `client.rental.getData` | `GET /api/rent.php?method=getdata` |
43
+ | `client.rental.get_data_with_providers` | `client.rental.getDataWithProviders` | `GET /api/rent.php?method=getdataWithProviders` |
44
+ | `client.rental.get_count` | `client.rental.getCount` | `GET /api/rent.php?method=getcount` |
45
+ | `client.rental.get_count_with_providers` | `client.rental.getCountWithProviders` | `GET /api/rent.php?method=getCountWithProviders` |
46
+ | `client.rental.get_multi_service_count` | `client.rental.getMultiServiceCount` | `GET /api/rent.php?method=get_count_multi` |
47
+ | `client.rental.get_canada_paypal_days` | `client.rental.getCanadaPaypalDays` | `GET /api/rent.php?method=get_days_canada_paypal` |
48
+ | `client.rental.get_minimum_paypal_days` | `client.rental.getMinimumPaypalDays` | `GET /api/rent.php?method=get_min_paypal_days` |
49
+ | `client.rental.create` | `client.rental.create` | `GET /api/rent.php?method=create` |
50
+ | `client.rental.create_multi` | `client.rental.createMulti` | `GET /api/rent.php?method=create_multi` |
51
+ | `client.rental.add_service_to_order` | `client.rental.addServiceToOrder` | `GET /api/rent.php?method=add_service_to_order` |
52
+ | `client.rental.get_orders` | `client.rental.getOrders` | `GET /api/rent.php?method=orders` |
53
+ | `client.rental.activate` | `client.rental.activate` | `GET /api/rent.php?method=activate` |
54
+ | `client.rental.get_sms` | `client.rental.getSms` | `GET /api/rent.php?method=sms` |
55
+ | `client.rental.get_prolong_price` | `client.rental.getProlongPrice` | `GET /api/rent.php?method=get_prolong_price` |
56
+ | `client.rental.prolong` | `client.rental.prolong` | `GET /api/rent.php?method=prolong` |
57
+ | `client.rental.prolong_by_days` | `client.rental.prolongByDays` | `GET /api/rent.php?method=prolong_max` |
58
+ | `client.rental.delete_order` | `client.rental.deleteOrder` | `GET /api/rent.php?method=delete` |
59
+ | `client.rental.get_history` | `client.rental.getHistory` | `GET /api/rent.php?method=get_rent_history` |
60
+ | `client.rental.get_restore_cost` | `client.rental.getRestoreCost` | `GET /api/rent.php?method=restore_user_precalc` |
61
+ | `client.rental.restore` | `client.rental.restore` | `GET /api/rent.php?method=restore_user` |
62
+
63
+ ## email
64
+
65
+ | Python (sync and async) | JavaScript / TypeScript | HTTP |
66
+ | --- | --- | --- |
67
+ | `client.email.get_providers` | `client.email.getProviders` | `GET /api/rent_email.php?method=get_providers` |
68
+ | `client.email.get_data` | `client.email.getData` | `GET /api/rent_email.php?method=get_data` |
69
+ | `client.email.get_count` | `client.email.getCount` | `GET /api/rent_email.php?method=get_count` |
70
+ | `client.email.create_order` | `client.email.createOrder` | `GET /api/rent_email.php?method=create_order` |
71
+ | `client.email.get_orders` | `client.email.getOrders` | `GET /api/rent_email.php?method=get_orders` |
72
+ | `client.email.get_mails` | `client.email.getMails` | `GET /api/rent_email.php?method=get_mails` |
73
+ | `client.email.get_mail_body` | `client.email.getMailBody` | `GET /api/rent_email.php?method=get_mail_body` |
74
+ | `client.email.buy_alias` | `client.email.buyAlias` | `GET /api/rent_email.php?method=buy_alias` |
75
+ | `client.email.get_mails_by_alias` | `client.email.getMailsByAlias` | `GET /api/rent_email.php?method=get_mails_by_alias` |
76
+ | `client.email.prolong_order` | `client.email.prolongOrder` | `GET /api/rent_email.php?method=prolong_order` |
77
+ | `client.email.cancel_order` | `client.email.cancelOrder` | `GET /api/rent_email.php?method=cancel_order` |
78
+ | `client.email.get_archived_orders` | `client.email.getArchivedOrders` | `GET /api/rent_email.php?method=get_archived_orders` |
79
+ | `client.email.calc_restore_order` | `client.email.calcRestoreOrder` | `GET /api/rent_email.php?method=calc_restore_order` |
80
+ | `client.email.restore_order` | `client.email.restoreOrder` | `GET /api/rent_email.php?method=restore_order` |
81
+
82
+ Activation also provides `wait_for_sms` / `waitForSms`. It polls an existing order until a caller-supplied expiry, without purchasing or cancelling an order.
@@ -0,0 +1,192 @@
1
+ Metadata-Version: 2.4
2
+ Name: smspva-sdk
3
+ Version: 0.1.0
4
+ Summary: Official Python SDK for SMSPVA SMS activation, phone number rental and private email APIs, with sync and async clients
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://smspva.com/
7
+ Project-URL: Documentation, https://docs.smspva.com
8
+ Project-URL: Repository, https://github.com/SMSPVA/smspva-python
9
+ Project-URL: Issues, https://github.com/SMSPVA/smspva-python/issues
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Typing :: Typed
12
+ Classifier: Programming Language :: Python :: 3
13
+ Requires-Python: >=3.10
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: httpx<1,>=0.28
17
+ Requires-Dist: typing_extensions>=4.12
18
+ Dynamic: license-file
19
+
20
+ # SMSPVA Python SDK
21
+
22
+ [![CI](https://github.com/SMSPVA/smspva-python/actions/workflows/ci.yml/badge.svg)](https://github.com/SMSPVA/smspva-python/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/SMSPVA/smspva-python/blob/main/LICENSE)
23
+
24
+ Official Python client for [SMSPVA](https://smspva.com/), a service for receiving verification SMS, renting phone numbers and renting private email addresses. Integrate these APIs into Python applications with synchronous **SMSPVA** and asynchronous **AsyncSMSPVA** clients.
25
+
26
+ Requires Python 3.10 or later. Includes typed parameters and response dictionaries.
27
+
28
+ ## Installation
29
+
30
+ ```sh
31
+ python -m pip install smspva-sdk
32
+ # Or pin this release:
33
+ python -m pip install smspva-sdk==0.1.0
34
+ ```
35
+
36
+ ## API coverage
37
+
38
+ The SDK provides 62 methods across three APIs:
39
+
40
+ | API | Methods | Use it to |
41
+ | --- | --- | --- |
42
+ | Activation V2 | 20 | Request a number, check availability and receive verification SMS. |
43
+ | Rental | 23 | Manage [phone number rentals](https://smspva.com/rent) and retrieve messages for existing orders. |
44
+ | Private Email | 14 | Check providers and services, manage [private email rentals](https://smspva.com/rent-mail.html), and read incoming messages. |
45
+
46
+ Country, service and provider lists come from the live API. Availability and prices can change. Alternative API is not included.
47
+
48
+ ## Quickstart
49
+
50
+ [Sign in to your SMSPVA account](https://smspva.com/signin.html) and open **Profile and ApiKey** from the account menu. Set the key as the **SMSPVA_API_KEY** environment variable before running a protected request. Keep it on your server and out of source control.
51
+
52
+ The examples below read your balance and reference data; they do not create an order.
53
+
54
+ ### Synchronous client
55
+
56
+ ```python
57
+ import os
58
+ from smspva import SMSPVA
59
+
60
+ with SMSPVA(os.environ["SMSPVA_API_KEY"]) as client:
61
+ print(client.activation.get_balance())
62
+ print(client.rental.get_countries())
63
+ print(client.email.get_providers())
64
+ ```
65
+
66
+ ### Asynchronous client
67
+
68
+ ```python
69
+ import asyncio
70
+ import os
71
+ from smspva import AsyncSMSPVA
72
+
73
+ async def main():
74
+ async with AsyncSMSPVA(os.environ["SMSPVA_API_KEY"]) as client:
75
+ result = await client.activation.get_balance()
76
+ print(result)
77
+
78
+ asyncio.run(main())
79
+ ```
80
+
81
+ Use the client as a context manager, or call `close()` / `await aclose()` yourself. Async uses HTTPX `AsyncClient`, not worker threads.
82
+
83
+ ## Requests and results
84
+
85
+ - Activation V2 sends the key in the `apikey` header. Rental and Email use the `apikey` query parameter. Public methods send no key or cookies. Optional-key rental methods use the client key unless you pass `use_api_key=False`.
86
+ - Returned dictionaries preserve wire field names and values, including string prices, timestamps, and IDs. Types follow the source schemas; a field not marked required remains optional.
87
+ - `is_pending(result)` recognises Activation SMS HTTP 202 / `SMS_NOT_YET_RECEIVED`. `is_no_stock(result)` recognises Email creation `status=2`. Both return the original response instead of raising a generic error.
88
+ - All documented optional parameters are available, including `partnerkey`, `partner_key`, `provider`, `extend`, pagination and search. Query and path values are encoded. Email `pcode=None` or `pcode=""` is omitted entirely.
89
+ - `rental.get_multi_service_count` requires explicit `dtype` and `dcount` because the docs warn that backend defaults are unreliable. The wire method remains `get_count_multi`.
90
+
91
+ ```python
92
+ # Public reference data, without an API key.
93
+ with SMSPVA() as client:
94
+ services = client.email.get_data(pcode="CODE_FROM_GET_PROVIDERS")
95
+ ```
96
+
97
+ Paid example (run only when you intend to create a rental):
98
+
99
+ ```python
100
+ from smspva import is_no_stock
101
+
102
+ with SMSPVA(os.environ["SMSPVA_API_KEY"]) as client:
103
+ result = client.email.create_order(
104
+ scode="CODE_FROM_GET_DATA", dtype="week", dcount=1
105
+ )
106
+ if is_no_stock(result):
107
+ print("No mailbox available; refresh counts before trying again.")
108
+ else:
109
+ print(result)
110
+ ```
111
+
112
+ ## Waiting for SMS
113
+
114
+ Save an expiry once when the number is created. `wait_for_sms` polls only Receive SMS, never creates another order, and stops on terminal errors, expiry or a transport failure. A new SMS retrieval can trigger payment.
115
+
116
+ ```python
117
+ import time
118
+
119
+ # number_result is the successful response from your own get_number request.
120
+ expires_at = time.time() + number_result["data"]["orderExpireIn"]
121
+ result = client.activation.wait_for_sms(
122
+ orderid=number_result["data"]["orderId"], expires_at=expires_at
123
+ )
124
+ ```
125
+
126
+ Use `await client.activation.wait_for_sms(...)` with `AsyncSMSPVA`. The helper waits at least five seconds between pending responses; this is a helper policy, not a claim about an API-wide rate limit. Request deadlines are bounded by the saved expiry. HTTPX timeouts apply to individual network operations; the async polling helper also enforces an overall remaining deadline.
127
+
128
+ ## Errors and timeouts
129
+
130
+ `ApiError` retains `family`, `operation`, `http_status`, `code` and the original `response`. `ProtocolError` means the body was not a usable JSON envelope. `TransportError` and `RequestTimeoutError` mean the request outcome may be unknown (`outcome_unknown` for state-changing/paid methods). No requests are retried automatically; inspect current orders before repeating a paid operation.
131
+
132
+ Exception messages omit request URLs and keys. Query credentials may still appear if you enable HTTPX request logging; redact those logs. Do not put account keys in browser code.
133
+
134
+ The default timeout is 30 seconds per HTTPX network operation. Override at client construction or per call with `timeout=...`. Advanced transports, proxies and test doubles can be supplied through `transport=httpx.HTTPTransport(...)` or `httpx.AsyncHTTPTransport(...)`; environment proxies/cookies are not inherited. Redirects are never followed.
135
+
136
+ The generated method index is in `METHODS.md`. Response TypedDicts and input aliases are available in `smspva.types`; the package includes `py.typed`.
137
+
138
+ ## Development
139
+
140
+ To build from source and run the local checks:
141
+
142
+ ```sh
143
+ git clone https://github.com/SMSPVA/smspva-python.git
144
+ cd smspva-python
145
+ python -m pip install -e . build mypy
146
+ python -m unittest discover -s tests -v
147
+ python -m mypy
148
+ python -m build
149
+ ```
150
+
151
+ Tests use synthetic fixtures and local transports; they do not buy numbers or call the production API.
152
+
153
+ ## Documentation and support
154
+
155
+ Read the [SMSPVA API documentation](https://docs.smspva.com/) for endpoint parameters, response codes and the activation, rental and email workflows. The [method index](https://github.com/SMSPVA/smspva-python/blob/main/METHODS.md) maps every SDK method to its API operation.
156
+
157
+ For account, billing or service questions, visit the [SMSPVA help center](https://smspva.com/help.html). Report SDK bugs through this repository's issues, without API keys or private message content.
158
+
159
+ ## License
160
+
161
+ MIT. See [LICENSE](https://github.com/SMSPVA/smspva-python/blob/main/LICENSE).
162
+
163
+ ## Compact number counts and operator ratings
164
+
165
+ Using an already configured client:
166
+
167
+ ```python
168
+ all_counts = client.activation.get_all_number_counts_compact()
169
+ ua_counts = client.activation.get_country_number_counts_compact(country="ua")
170
+
171
+ # With an AsyncSMSPVA client:
172
+ async def read_counts(async_client):
173
+ all_counts = await async_client.activation.get_all_number_counts_compact()
174
+ ua_counts = await async_client.activation.get_country_number_counts_compact(country="ua")
175
+ return all_counts, ua_counts
176
+ ```
177
+
178
+ Both requests use GET and the account API key in the `apikey` header. Country codes are case-insensitive; an unknown country returns `data: []`. No extra query parameters are required. Results are cached by the API for 60 seconds, independently for all countries and for each country.
179
+
180
+ The SDK preserves `Operator`, `Country`, `Services`, `Rating` and `ServiceRatings` exactly as returned, including negative counts and missing or invalid ratings. It does not insert computed rating fields. For non-`Donor*` operators, the effective rating is 1. For `Donor*` operators, use a service rating if it is an integer from 1 to 10, then a valid overall rating; otherwise the rating is undefined. Lower is better.
181
+
182
+ ## Receive another SMS on a previously used number
183
+
184
+ Call the Activation methods in this order: `repeat_number`, `get_phone_status`, `start_sms`, `receive_sms`. Use a number previously paid for on the same service and carry the new order ID through the remaining calls. Request a new code in the target service after starting SMS reception.
185
+
186
+ HTTP 202 with NUMBER_NOT_READY includes retryAfter in seconds. For PHONE_NOT_READY, wait five seconds. Wait 30 seconds between SMS checks while the order is active. Receiving a new paid SMS can incur a charge. If the number request has an uncertain outcome, inspect current orders before retrying.
187
+
188
+ ## Rental pricing and partial results
189
+
190
+ The SDK includes `client.rental.get_prolong_price` to quote an active rental extension before paying. Send the order `id` and actual number of `days`; read `data.price` in USD. The quote does not extend the rental. See the [extension price reference](https://docs.smspva.com/en/docs/rental/prolong-price/).
191
+
192
+ Use optional `operator_prices=1` with countries-by-service or data-by-provider calls to request operator tariffs. Price entries do not imply stock; inspect the corresponding counts. `catalogue_rate` can be absent when no operator has stock. Multi-service creation can return order objects and error strings in the same `data` array even when `status=1`: inspect each item and do not retry the whole purchase automatically. Responses preserve the API values, including string or integer `until` fields.
@@ -0,0 +1,173 @@
1
+ # SMSPVA Python SDK
2
+
3
+ [![CI](https://github.com/SMSPVA/smspva-python/actions/workflows/ci.yml/badge.svg)](https://github.com/SMSPVA/smspva-python/actions/workflows/ci.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/SMSPVA/smspva-python/blob/main/LICENSE)
4
+
5
+ Official Python client for [SMSPVA](https://smspva.com/), a service for receiving verification SMS, renting phone numbers and renting private email addresses. Integrate these APIs into Python applications with synchronous **SMSPVA** and asynchronous **AsyncSMSPVA** clients.
6
+
7
+ Requires Python 3.10 or later. Includes typed parameters and response dictionaries.
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ python -m pip install smspva-sdk
13
+ # Or pin this release:
14
+ python -m pip install smspva-sdk==0.1.0
15
+ ```
16
+
17
+ ## API coverage
18
+
19
+ The SDK provides 62 methods across three APIs:
20
+
21
+ | API | Methods | Use it to |
22
+ | --- | --- | --- |
23
+ | Activation V2 | 20 | Request a number, check availability and receive verification SMS. |
24
+ | Rental | 23 | Manage [phone number rentals](https://smspva.com/rent) and retrieve messages for existing orders. |
25
+ | Private Email | 14 | Check providers and services, manage [private email rentals](https://smspva.com/rent-mail.html), and read incoming messages. |
26
+
27
+ Country, service and provider lists come from the live API. Availability and prices can change. Alternative API is not included.
28
+
29
+ ## Quickstart
30
+
31
+ [Sign in to your SMSPVA account](https://smspva.com/signin.html) and open **Profile and ApiKey** from the account menu. Set the key as the **SMSPVA_API_KEY** environment variable before running a protected request. Keep it on your server and out of source control.
32
+
33
+ The examples below read your balance and reference data; they do not create an order.
34
+
35
+ ### Synchronous client
36
+
37
+ ```python
38
+ import os
39
+ from smspva import SMSPVA
40
+
41
+ with SMSPVA(os.environ["SMSPVA_API_KEY"]) as client:
42
+ print(client.activation.get_balance())
43
+ print(client.rental.get_countries())
44
+ print(client.email.get_providers())
45
+ ```
46
+
47
+ ### Asynchronous client
48
+
49
+ ```python
50
+ import asyncio
51
+ import os
52
+ from smspva import AsyncSMSPVA
53
+
54
+ async def main():
55
+ async with AsyncSMSPVA(os.environ["SMSPVA_API_KEY"]) as client:
56
+ result = await client.activation.get_balance()
57
+ print(result)
58
+
59
+ asyncio.run(main())
60
+ ```
61
+
62
+ Use the client as a context manager, or call `close()` / `await aclose()` yourself. Async uses HTTPX `AsyncClient`, not worker threads.
63
+
64
+ ## Requests and results
65
+
66
+ - Activation V2 sends the key in the `apikey` header. Rental and Email use the `apikey` query parameter. Public methods send no key or cookies. Optional-key rental methods use the client key unless you pass `use_api_key=False`.
67
+ - Returned dictionaries preserve wire field names and values, including string prices, timestamps, and IDs. Types follow the source schemas; a field not marked required remains optional.
68
+ - `is_pending(result)` recognises Activation SMS HTTP 202 / `SMS_NOT_YET_RECEIVED`. `is_no_stock(result)` recognises Email creation `status=2`. Both return the original response instead of raising a generic error.
69
+ - All documented optional parameters are available, including `partnerkey`, `partner_key`, `provider`, `extend`, pagination and search. Query and path values are encoded. Email `pcode=None` or `pcode=""` is omitted entirely.
70
+ - `rental.get_multi_service_count` requires explicit `dtype` and `dcount` because the docs warn that backend defaults are unreliable. The wire method remains `get_count_multi`.
71
+
72
+ ```python
73
+ # Public reference data, without an API key.
74
+ with SMSPVA() as client:
75
+ services = client.email.get_data(pcode="CODE_FROM_GET_PROVIDERS")
76
+ ```
77
+
78
+ Paid example (run only when you intend to create a rental):
79
+
80
+ ```python
81
+ from smspva import is_no_stock
82
+
83
+ with SMSPVA(os.environ["SMSPVA_API_KEY"]) as client:
84
+ result = client.email.create_order(
85
+ scode="CODE_FROM_GET_DATA", dtype="week", dcount=1
86
+ )
87
+ if is_no_stock(result):
88
+ print("No mailbox available; refresh counts before trying again.")
89
+ else:
90
+ print(result)
91
+ ```
92
+
93
+ ## Waiting for SMS
94
+
95
+ Save an expiry once when the number is created. `wait_for_sms` polls only Receive SMS, never creates another order, and stops on terminal errors, expiry or a transport failure. A new SMS retrieval can trigger payment.
96
+
97
+ ```python
98
+ import time
99
+
100
+ # number_result is the successful response from your own get_number request.
101
+ expires_at = time.time() + number_result["data"]["orderExpireIn"]
102
+ result = client.activation.wait_for_sms(
103
+ orderid=number_result["data"]["orderId"], expires_at=expires_at
104
+ )
105
+ ```
106
+
107
+ Use `await client.activation.wait_for_sms(...)` with `AsyncSMSPVA`. The helper waits at least five seconds between pending responses; this is a helper policy, not a claim about an API-wide rate limit. Request deadlines are bounded by the saved expiry. HTTPX timeouts apply to individual network operations; the async polling helper also enforces an overall remaining deadline.
108
+
109
+ ## Errors and timeouts
110
+
111
+ `ApiError` retains `family`, `operation`, `http_status`, `code` and the original `response`. `ProtocolError` means the body was not a usable JSON envelope. `TransportError` and `RequestTimeoutError` mean the request outcome may be unknown (`outcome_unknown` for state-changing/paid methods). No requests are retried automatically; inspect current orders before repeating a paid operation.
112
+
113
+ Exception messages omit request URLs and keys. Query credentials may still appear if you enable HTTPX request logging; redact those logs. Do not put account keys in browser code.
114
+
115
+ The default timeout is 30 seconds per HTTPX network operation. Override at client construction or per call with `timeout=...`. Advanced transports, proxies and test doubles can be supplied through `transport=httpx.HTTPTransport(...)` or `httpx.AsyncHTTPTransport(...)`; environment proxies/cookies are not inherited. Redirects are never followed.
116
+
117
+ The generated method index is in `METHODS.md`. Response TypedDicts and input aliases are available in `smspva.types`; the package includes `py.typed`.
118
+
119
+ ## Development
120
+
121
+ To build from source and run the local checks:
122
+
123
+ ```sh
124
+ git clone https://github.com/SMSPVA/smspva-python.git
125
+ cd smspva-python
126
+ python -m pip install -e . build mypy
127
+ python -m unittest discover -s tests -v
128
+ python -m mypy
129
+ python -m build
130
+ ```
131
+
132
+ Tests use synthetic fixtures and local transports; they do not buy numbers or call the production API.
133
+
134
+ ## Documentation and support
135
+
136
+ Read the [SMSPVA API documentation](https://docs.smspva.com/) for endpoint parameters, response codes and the activation, rental and email workflows. The [method index](https://github.com/SMSPVA/smspva-python/blob/main/METHODS.md) maps every SDK method to its API operation.
137
+
138
+ For account, billing or service questions, visit the [SMSPVA help center](https://smspva.com/help.html). Report SDK bugs through this repository's issues, without API keys or private message content.
139
+
140
+ ## License
141
+
142
+ MIT. See [LICENSE](https://github.com/SMSPVA/smspva-python/blob/main/LICENSE).
143
+
144
+ ## Compact number counts and operator ratings
145
+
146
+ Using an already configured client:
147
+
148
+ ```python
149
+ all_counts = client.activation.get_all_number_counts_compact()
150
+ ua_counts = client.activation.get_country_number_counts_compact(country="ua")
151
+
152
+ # With an AsyncSMSPVA client:
153
+ async def read_counts(async_client):
154
+ all_counts = await async_client.activation.get_all_number_counts_compact()
155
+ ua_counts = await async_client.activation.get_country_number_counts_compact(country="ua")
156
+ return all_counts, ua_counts
157
+ ```
158
+
159
+ Both requests use GET and the account API key in the `apikey` header. Country codes are case-insensitive; an unknown country returns `data: []`. No extra query parameters are required. Results are cached by the API for 60 seconds, independently for all countries and for each country.
160
+
161
+ The SDK preserves `Operator`, `Country`, `Services`, `Rating` and `ServiceRatings` exactly as returned, including negative counts and missing or invalid ratings. It does not insert computed rating fields. For non-`Donor*` operators, the effective rating is 1. For `Donor*` operators, use a service rating if it is an integer from 1 to 10, then a valid overall rating; otherwise the rating is undefined. Lower is better.
162
+
163
+ ## Receive another SMS on a previously used number
164
+
165
+ Call the Activation methods in this order: `repeat_number`, `get_phone_status`, `start_sms`, `receive_sms`. Use a number previously paid for on the same service and carry the new order ID through the remaining calls. Request a new code in the target service after starting SMS reception.
166
+
167
+ HTTP 202 with NUMBER_NOT_READY includes retryAfter in seconds. For PHONE_NOT_READY, wait five seconds. Wait 30 seconds between SMS checks while the order is active. Receiving a new paid SMS can incur a charge. If the number request has an uncertain outcome, inspect current orders before retrying.
168
+
169
+ ## Rental pricing and partial results
170
+
171
+ The SDK includes `client.rental.get_prolong_price` to quote an active rental extension before paying. Send the order `id` and actual number of `days`; read `data.price` in USD. The quote does not extend the rental. See the [extension price reference](https://docs.smspva.com/en/docs/rental/prolong-price/).
172
+
173
+ Use optional `operator_prices=1` with countries-by-service or data-by-provider calls to request operator tariffs. Price entries do not imply stock; inspect the corresponding counts. `catalogue_rate` can be absent when no operator has stock. Multi-service creation can return order objects and error strings in the same `data` array even when `status=1`: inspect each item and do not retry the whole purchase automatically. Responses preserve the API values, including string or integer `until` fields.
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "smspva-sdk"
7
+ version = "0.1.0"
8
+ description = "Official Python SDK for SMSPVA SMS activation, phone number rental and private email APIs, with sync and async clients"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.10"
13
+ dependencies = ["httpx>=0.28,<1", "typing_extensions>=4.12"]
14
+ classifiers = ["Development Status :: 5 - Production/Stable", "Typing :: Typed", "Programming Language :: Python :: 3"]
15
+
16
+ [tool.setuptools.packages.find]
17
+ where = ["src"]
18
+
19
+ [tool.setuptools.package-data]
20
+ smspva = ["py.typed", "_contracts.json"]
21
+
22
+ [tool.mypy]
23
+ python_version = "3.10"
24
+ strict = true
25
+ files = ["src/smspva"]
26
+
27
+ [tool.setuptools]
28
+ include-package-data = true
29
+
30
+ [project.urls]
31
+ Homepage = "https://smspva.com/"
32
+ Documentation = "https://docs.smspva.com"
33
+ Repository = "https://github.com/SMSPVA/smspva-python"
34
+ Issues = "https://github.com/SMSPVA/smspva-python/issues"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,6 @@
1
+ from ._client import SMSPVA, AsyncSMSPVA
2
+ from ._polling import is_pending, is_no_stock
3
+ from .errors import SMSPVAError, ApiError, ProtocolError, TransportError, RequestTimeoutError, PollingTimeoutError, ValidationError
4
+
5
+ __version__ = "0.1.0"
6
+ __all__ = ["SMSPVA", "AsyncSMSPVA", "is_pending", "is_no_stock", "SMSPVAError", "ApiError", "ProtocolError", "TransportError", "RequestTimeoutError", "PollingTimeoutError", "ValidationError"]
@@ -0,0 +1,43 @@
1
+ from __future__ import annotations
2
+
3
+ from types import TracebackType
4
+ import httpx
5
+
6
+ from ._transport import Transport, AsyncTransport
7
+ from ._resources import Activation, Rental, Email, AsyncActivation, AsyncRental, AsyncEmail
8
+
9
+
10
+ class SMSPVA:
11
+ def __init__(self, api_key: str | None = None, *, timeout: float = 30, activation_base_url: str | None = None,
12
+ rental_base_url: str | None = None, email_base_url: str | None = None, transport: httpx.BaseTransport | None = None):
13
+ self._transport = Transport(api_key, timeout, {"activation": activation_base_url, "rental": rental_base_url, "email": email_base_url}, transport)
14
+ self.activation = Activation(self._transport)
15
+ self.rental = Rental(self._transport)
16
+ self.email = Email(self._transport)
17
+
18
+ def close(self) -> None:
19
+ self._transport.close()
20
+
21
+ def __enter__(self) -> SMSPVA:
22
+ return self
23
+
24
+ def __exit__(self, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None:
25
+ self.close()
26
+
27
+
28
+ class AsyncSMSPVA:
29
+ def __init__(self, api_key: str | None = None, *, timeout: float = 30, activation_base_url: str | None = None,
30
+ rental_base_url: str | None = None, email_base_url: str | None = None, transport: httpx.AsyncBaseTransport | None = None):
31
+ self._transport = AsyncTransport(api_key, timeout, {"activation": activation_base_url, "rental": rental_base_url, "email": email_base_url}, transport)
32
+ self.activation = AsyncActivation(self._transport)
33
+ self.rental = AsyncRental(self._transport)
34
+ self.email = AsyncEmail(self._transport)
35
+
36
+ async def aclose(self) -> None:
37
+ await self._transport.close()
38
+
39
+ async def __aenter__(self) -> AsyncSMSPVA:
40
+ return self
41
+
42
+ async def __aexit__(self, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None:
43
+ await self.aclose()