Metadata-Version: 2.4
Name: serwersmsv2api
Version: 2.0.0
Summary: Python client for SerwerSMS.pl API v2
Author-email: SerwerSMS <integrations@serwersms.pl>
License-Expression: Apache-2.0
Project-URL: Homepage, https://serwersms.pl
Project-URL: Documentation, https://dev.serwersms.pl
Project-URL: Repository, https://github.com/SerwerSMSpl/serwersms-python-api
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28
Dynamic: license-file

# SerwerSMS.pl Python Client API

🇵🇱 [Polski](#polski) | 🇬🇧 [English](#english)

---

<a name="polski"></a>
# Polski

Klient Python do komunikacji zdalnej z API v2 SerwerSMS.pl

Aktualna wersja działa w oparciu o token API.

W celu autoryzacji za pośrednictwem Tokenu API, należy wygenerować go po stronie Panelu Klienta w menu Ustawienia interfejsów → HTTP API → Tokeny API. Format nagłówka autoryzacyjnego jest zgodny z formatem Bearer token.

## Instalacja

```
pip install serwersmsv2api
```

Szczegóły dostępne są pod adresem https://pypi.org/project/serwersmsv2api/

## Wymagania
- Python >= 3.12
- requests

## Przykłady użycia

#### Przykładowe wywołanie

```python
import sys
import json
import serwersms
from serwersms import SerwerSMSException

try:

    api = serwersms.SerwerSMS('token')

    params = {
        'test': 'true',
        'details': 'true'
    }

    response = api.message.send_sms('500600700', 'Test message', 'INFORMACJA', params)

    result = json.loads(response)

    if 'items' not in result:
        raise Exception('Empty items')

    for item in result['items']:
        print(item['id'] + ' - ' + item['phone'] + ' - ' + item['status'])

except SerwerSMSException as e:

    print('API ERROR: ', e)
    print('HTTP status: ', e.http_status_code)

except Exception:

    print('ERROR: ', sys.exc_info()[1])
```

#### Wysyłka SMS

```python
api = serwersms.SerwerSMS('token')

try:

    params = {
        'details': 'true'
    }

    response = api.message.send_sms('500600700', 'Test message', 'INFORMACJA', params)

    print(response)

except SerwerSMSException as e:

    print('API ERROR: ', e)
```

#### Wysyłka spersonalizowanych SMS

```python
api = serwersms.SerwerSMS('token')

try:

    messages = [
        {'phone': '500600700', 'text': 'First message'},
        {'phone': '600700800', 'text': 'Second message'},
    ]

    params = {
        'details': 'true'
    }

    response = api.message.send_personalized(messages, 'INFORMACJA', params)

    print(response)

except SerwerSMSException as e:

    print('API ERROR: ', e)
```

#### Pobieranie raportów doręczeń

```python
api = serwersms.SerwerSMS('token')

try:

    params = {
        'id': 'aca3944055'
    }

    response = api.message.reports(params)

    print(response)

except SerwerSMSException as e:

    print('API ERROR: ', e)
```

#### Pobieranie wiadomości przychodzących

```python
api = serwersms.SerwerSMS('token')

try:

    params = {
        'phone': '500600700'
    }

    response = api.message.received('ndi', params)

    print(response)

except SerwerSMSException as e:

    print('API ERROR: ', e)
```

#### Ustawienie limitu czasu połączenia

```python
api = serwersms.SerwerSMS('token')
api.set_timeout(10, 30)
```

## Dokumentacja
https://dev.serwersms.pl

## Konsola API
https://apiconsole.serwersms.pl

---

<a name="english"></a>
# English

Python client for remote communication with SerwerSMS.pl API v2.

This version uses API token authorization.

To authorize via API Token, generate it in the Client Panel under Settings → HTTP API → API Tokens. The authorization header format follows the Bearer token standard.

## Installation

```
pip install serwersmsv2api
```

Details available at https://pypi.org/project/serwersmsv2api/

## Requirements
- Python >= 3.12
- requests

## Usage examples

#### Basic example

```python
import sys
import json
import serwersms
from serwersms import SerwerSMSException

try:

    api = serwersms.SerwerSMS('token')

    params = {
        'test': 'true',
        'details': 'true'
    }

    response = api.message.send_sms('500600700', 'Test message', 'INFORMACJA', params)

    result = json.loads(response)

    if 'items' not in result:
        raise Exception('Empty items')

    for item in result['items']:
        print(item['id'] + ' - ' + item['phone'] + ' - ' + item['status'])

except SerwerSMSException as e:

    print('API ERROR: ', e)
    print('HTTP status: ', e.http_status_code)

except Exception:

    print('ERROR: ', sys.exc_info()[1])
```

#### Send SMS

```python
api = serwersms.SerwerSMS('token')

try:

    params = {
        'details': 'true'
    }

    response = api.message.send_sms('500600700', 'Test message', 'INFORMACJA', params)

    print(response)

except SerwerSMSException as e:

    print('API ERROR: ', e)
```

#### Send personalized SMS

```python
api = serwersms.SerwerSMS('token')

try:

    messages = [
        {'phone': '500600700', 'text': 'First message'},
        {'phone': '600700800', 'text': 'Second message'},
    ]

    params = {
        'details': 'true'
    }

    response = api.message.send_personalized(messages, 'INFORMACJA', params)

    print(response)

except SerwerSMSException as e:

    print('API ERROR: ', e)
```

#### Get delivery reports

```python
api = serwersms.SerwerSMS('token')

try:

    params = {
        'id': 'aca3944055'
    }

    response = api.message.reports(params)

    print(response)

except SerwerSMSException as e:

    print('API ERROR: ', e)
```

#### Get received messages

```python
api = serwersms.SerwerSMS('token')

try:

    params = {
        'phone': '500600700'
    }

    response = api.message.received('ndi', params)

    print(response)

except SerwerSMSException as e:

    print('API ERROR: ', e)
```

#### Set connection timeout

```python
api = serwersms.SerwerSMS('token')
api.set_timeout(10, 30)
```

## Documentation
https://dev.serwersms.pl

## API Console
https://apiconsole.serwersms.pl
