Skip to main content

Python SDK for Kirim.Email SMTP API

Project description

Kirim.Email SMTP Python SDK

Python SDK for Kirim.Email SMTP API - A modern, type-safe Python client for sending emails and managing SMTP services.

Features

  • 🚀 Modern Python with full type hints
  • ⚡ Async/await support with httpx
  • 📝 Pydantic models for data validation
  • 🔄 Comprehensive error handling
  • 📎 File attachment support
  • 📊 Email log streaming
  • 🧪 Full test coverage
  • 📦 Minimal dependencies

Installation

pip install kirimemail-smtp-sdk

Quick Start

import asyncio
from kirimemail_smtp import SmtpClient, MessagesApi

async def send_email():
    # Initialize client
    client = SmtpClient(username="your-username", token="your-token")
    messages_api = MessagesApi(client)
    
    # Send email
    result = await messages_api.send_message(
        domain="example.com",
        message={
            "from": "sender@example.com",
            "from_name": "Company Name",
            "to": "recipient@example.com",
            "subject": "Hello from Python SDK",
            "text": "This is a test email sent using the Kirim.Email Python SDK."
        }
    )
    
    print(f"Email sent: {result}")

# Run the async function
asyncio.run(send_email())

API Reference

Client

The SmtpClient is the core HTTP client with authentication and error handling.

from kirimemail_smtp import SmtpClient

client = SmtpClient(
    username="your-username",
    token="your-token",
    base_url="https://smtp-app.kirim.email"  # Optional, defaults to production
)

Messages API

Send emails and templates:

from kirimemail_smtp import MessagesApi

messages_api = MessagesApi(client)

# Send simple email
await messages_api.send_message(domain="example.com", message={
    "from": "sender@example.com",
    "from_name": "Company Name",
    "to": "recipient@example.com",
    "subject": "Test Email",
    "text": "Email content"
})

# Send with attachments
await messages_api.send_message_with_attachments(
    domain="example.com",
    message={
        "from": "sender@example.com",
        "to": "recipient@example.com",
        "subject": "Email with attachments",
        "text": "Please find attached files"
    },
    files=[
        {"field": "attachment", "filename": "document.pdf", "content": b"PDF content"}
    ]
)

# Send template email
await messages_api.send_template_message(
    domain="example.com",
    template={
        "template_guid": "template-uuid",
        "from": "sender@example.com",
        "from_name": "Company Name",
        "to": "recipient@example.com",
        "variables": {"name": "John", "product": "Premium Plan"}
    }
)

Domains API

Manage domains:

from kirimemail_smtp import DomainsApi

domains_api = DomainsApi(client)

# List domains
domains = await domains_api.list_domains()

# Create domain
domain = await domains_api.create_domain(
    domain="newdomain.com",
    dkim_key_length=2048
)

# Get domain details
domain = await domains_api.get_domain("example.com")

# Update domain
await domains_api.update_domain("example.com", {
    "open_track": True,
    "click_track": True
})

Credentials API

Manage SMTP credentials:

from kirimemail_smtp import CredentialsApi

credentials_api = CredentialsApi(client)

# List credentials
credentials = await credentials_api.list_credentials("example.com")

# Create credential
credential = await credentials_api.create_credential(
    domain="example.com",
    username="new-credential"
)

# Delete credential
await credentials_api.delete_credential("example.com", "credential-username")

Logs API

Retrieve and stream email logs:

from kirimemail_smtp import LogsApi

logs_api = LogsApi(client)

# Get logs
logs = await logs_api.get_logs("example.com", {
    "limit": 50,
    "page": 1
})

# Stream logs (async generator)
async for log_entry in logs_api.stream_logs("example.com"):
    print(f"Log: {log_entry}")

Suppressions API

Manage email suppressions:

from kirimemail_smtp import SuppressionsApi

suppressions_api = SuppressionsApi(client)

# Get suppressions
suppressions = await suppressions_api.get_suppressions("example.com")

# Get suppressions by type
bounce_suppressions = await suppressions_api.get_suppressions_by_type(
    "example.com", "bounce"
)

Error Handling

The SDK provides comprehensive error handling with specific exception types:

from kirimemail_smtp.exceptions import (
    ApiException,
    AuthenticationException,
    ValidationException,
    NotFoundException,
    ServerException
)

try:
    await messages_api.send_message(domain="example.com", message=message_data)
except AuthenticationException:
    print("Authentication failed - check your credentials")
except ValidationException as e:
    print(f"Validation error: {e.message}")
    print(f"Field errors: {e.errors}")
except NotFoundException:
    print("Domain not found")
except ServerException:
    print("Server error - please try again later")
except ApiException as e:
    print(f"API error: {e.message}")

Development

Setup

# Clone repository
git clone https://github.com/kirimemail/kirimemail-smtp-python-sdk.git
cd kirimemail-smtp-python-sdk

# Install with uv
uv sync --dev

# Run tests
uv run pytest

# Run with coverage
uv run pytest --cov=src/kirimemail_smtp --cov-report=html

Code Quality

# Lint code
uv run ruff check src/

# Format code
uv run ruff format src/

# Type checking
uv run mypy src/

License

MIT License - see LICENSE file for details.

Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kirimemail_smtp_sdk-1.0.0.tar.gz (81.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kirimemail_smtp_sdk-1.0.0-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file kirimemail_smtp_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: kirimemail_smtp_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 81.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for kirimemail_smtp_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 760579275136e2225dd56cb52fe89e2e19810ab9ca97aba89b2306fdb2a04359
MD5 0f527db959f5a2c9d4e66f2e86372c64
BLAKE2b-256 e0c3fcfebfef069f8220f7655e25e216d13cb1d55479f61d6b9e2a45a3c5c032

See more details on using hashes here.

File details

Details for the file kirimemail_smtp_sdk-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for kirimemail_smtp_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43d76890b85ccff547c0df1f54c0309b584c8d64a0845558ad54441bd686242d
MD5 7789c8d00442a7e61cffc862bcafe19b
BLAKE2b-256 9315aecc7df6bc9c27eca17c6fc5140f7f80476e1532a8ce8d19ed0d89a0e1f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page