Skip to main content

İletiniz Python SDK

License: MIT

Iletiniz API için resmi Python SDK'si. Python 3.9+ üzerinde çalışır, hiçbir runtime bağımlılığı yoktur (yalnızca standart kütüphane).

Kurulum

pip install iletiniz

Gereksinimler:

  • Python >= 3.9

Hızlı başlangıç

import os
from iletiniz import IletinizClient

client = IletinizClient(api_key=os.environ["ILETINIZ_API_KEY"])  # 'iltz_live_…' veya 'iltz_test_…'

result = client.messages.send({
    "to": "+905551234567",
    "body": "Merhaba!",
})

print(result["job_id"], result["status"])

api_key verilmediğinde SDK ILETINIZ_API_KEY ortam değişkenini okur.

Yapılandırma

IletinizClient(
    api_key="iltz_live_…",
    base_url="https://api.iletiniz.com",  # varsayılan
    timeout_ms=30_000,                     # varsayılan
    max_retries=2,                         # 408/429/5xx ve ağ hatalarında
    default_headers={"X-Source": "crm"},
    transport=None,                        # özel Transport implementasyonu
)

Endpoint'ler

SDK, public API yüzeyini kapsar:

Metot HTTP
client.health.check() GET /v1/health
client.messages.send(params) POST /v1/messages
client.messages.send_bulk(params) POST /v1/messages/bulk
client.messages.retrieve(job_id) GET /v1/messages/{job_id}
client.messages.status(job_id) (alias) GET /v1/messages/{job_id}

Tek mesaj göndermek

client.messages.send({
    "to": "+905551234567",
    "body": "Sipariş kodunuz: 4821",
    "sender": "MAGAZA",     # opsiyonel
    "provider": "netgsm",   # opsiyonel
})

Telegram üzerinden göndermek

"provider": "telegram" seçildiğinde to alanı SMS yerine Telegram alıcı tanımlayıcısı bekler: numerik chat_id (örn 8409353994, gruplar için -1001234567890) veya @kullaniciadi. sender Telegram için kullanılmaz — bot kimliği bağlantıdaki token'a gömülüdür.

client.messages.send({
    "to": "8409353994",
    "body": "Merhaba!",
    "provider": "telegram",
})

Template ile göndermek

client.messages.send({
    "to": "+905551234567",
    "template": "order_shipped",
    "variables": {"name": "Ayşe", "tracking_no": "TR123"},
})

body ve template aynı anda kullanılamaz; tam olarak biri zorunludur. variables yalnızca template ile birlikte verilebilir.

Toplu gönderim

Tek istekte en fazla 200 öğe gönderebilirsiniz.

# Düz metin modu — her item'da body zorunlu, variables yok
client.messages.send_bulk({
    "items": [
        {"to": "+905551111111", "body": "Mesaj 1"},
        {"to": "+905552222222", "body": "Mesaj 2"},
    ],
})

# Template modu — items'ta body olmamalı
client.messages.send_bulk({
    "template": "low_stock_alert",
    "items": [
        {"to": "+905551111111", "variables": {"product": "Ürün A", "stock": 3}},
        {"to": "+905552222222", "variables": {"product": "Ürün B", "stock": 1}},
    ],
})

Mesaj durumunu sorgulamak

info = client.messages.retrieve(job_id)
# info["status"]: 'sent' | 'queued' | 'failed' | 'delivered' | 'expired' | 'rejected' | 'unknown'

Sağlık kontrolü

health = client.health.check()
# {"ok": True, "db": "up"}

Hata yönetimi

Tüm hatalar IletinizError sınıfından türetilir. HTTP status'a göre uygun alt sınıf raise edilir:

from iletiniz import (
    IletinizAPIError,
    IletinizAuthenticationError,
    IletinizConnectionError,
    IletinizNotFoundError,
    IletinizRateLimitError,
    IletinizServerError,
    IletinizTimeoutError,
    IletinizValidationError,
)

try:
    client.messages.send({"to": "+905551234567", "body": "test"})
except IletinizAuthenticationError:
    # 401 — geçersiz veya iptal edilmiş anahtar
    ...
except IletinizValidationError as e:
    # 400 / 422 — istek doğrulanamadı
    print(e.body)
except IletinizRateLimitError:
    # 429 — yeniden denemeden önce backoff
    ...
except IletinizNotFoundError:
    # 404
    ...
except IletinizServerError:
    # 5xx
    ...
except IletinizAPIError as e:
    print(e.status, e.code, str(e), e.request_id)
except IletinizTimeoutError:
    # istek timeout'a takıldı
    ...
except IletinizConnectionError:
    # ağ hatası
    ...

Yeniden deneme stratejisi

SDK, aşağıdaki durumlarda otomatik olarak max_retries defa yeniden dener (varsayılan: 2):

  • Ağ kaynaklı bağlantı hataları
  • HTTP 408, 429, 500–599

Retry-After başlığı varsa beklenir; aksi halde exponential backoff (jitter ile) uygulanır. Yeniden denemeyi kapatmak için max_retries=0 verin.

Timeout

Her istek için ayrıca timeout verebilirsiniz:

from iletiniz import RequestOptions

client.messages.send(
    {"to": "+905551234567", "body": "merhaba"},
    RequestOptions(timeout_ms=10_000),
)

Tip desteği

SDK tamamen tip ipuçlarıyla yazıldı (PEP 561 — py.typed). Tüm parametre ve yanıt tipleri export edilir:

from iletiniz import (
    HealthResponse,
    MessageStatusResponse,
    SendBulkParams,
    SendBulkResponse,
    SendMessageParams,
    SendMessageResponse,
)

Test

SDK, iletiniz.Transport protokolü üzerinden HTTP katmanını dışarı açar. Testlerinizde gerçek ağ trafiği oluşturmadan SDK'yı kullanabilirsiniz:

from iletiniz import HttpResponse, IletinizClient, Transport


class FakeTransport(Transport):
    def send(self, method, url, headers, body, timeout_ms):
        return HttpResponse(status=200, body=b'{"ok":true,"db":"up"}', headers={})


client = IletinizClient(api_key="iltz_test_xxx", transport=FakeTransport())

Katkıda Bulunma / Contributing

Katkı sağlamak ister misiniz? Lütfen CONTRIBUTING.md dosyasını inceleyin. English: CONTRIBUTING.en.md.

Davranış Kuralları / Code of Conduct

Bu proje Contributor Covenant davranış kurallarına bağlıdır. English: CODE_OF_CONDUCT.en.md.

Güvenlik / Security

Güvenlik açığı bildirmek için lütfen SECURITY.md dosyasındaki adımları izleyin — public issue açmayın. English: SECURITY.en.md.

Lisans / License

MIT — bkz. / see LICENSE.

Metadata

Release files for iletiniz 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iletiniz 0.1.0
File Size Uploaded Provenance Actions
iletiniz-0.1.0.tar.gz 11.0 kB Without provenance Details for iletiniz-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for iletiniz 0.1.0
File Interpreter ABI Platform Actions
iletiniz-0.1.0-py3-none-any.whl Python 3 none any Details for iletiniz-0.1.0-py3-none-any.whl

Total release size: 24.7 kB

Release files / iletiniz-0.1.0.tar.gz

Download URL iletiniz-0.1.0.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
de932b8642c6702eb8272740cdebb87eb4c4700d7d2ec20e272314f2a7aea553
BLAKE2b-256 checksum
How to use checksums
8d5ff4e336c99ead68e4c9e51eb0cdb06778ba498ab6a9d30dac2d51fe5b8580
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / iletiniz-0.1.0-py3-none-any.whl

Download URL iletiniz-0.1.0-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4f7c014ccb2de113740b28d284bba80d23e44d4ddb89efac9445bec79bd4b9f7
BLAKE2b-256 checksum
How to use checksums
de92e0047c3fdf7ba01c2a85daafdd18a6fe6a8ec087348db4e2cf238cb4def5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for iletiniz 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page