Skip to main content

Official Metigan SDK for Python - Email, Forms, Contacts, and Audiences management

Project description

Metigan Python SDK

Official Metigan SDK for Python. Send emails, manage forms, contacts, and audiences with ease.

📦 Installation

pip install metigan
# or
pip3 install metigan

🚀 Quick Start

from metigan import MetiganClient

# Initialize the client
client = MetiganClient(api_key="your-api-key")

# Send email
result = client.email.send_email(
    from_address="Sender <sender@example.com>",
    recipients=["customer@email.com"],
    subject="Welcome!",
    content="<h1>Hello!</h1><p>Thank you for signing up.</p>"
)

if result["success"]:
    print("Email sent successfully!")
    print(f"Emails remaining: {result.get('emailsRemaining', 'N/A')}")

📧 Email Module

Basic Send

result = client.email.send_email(
    from_address="sender@example.com",
    recipients=["recipient@example.com"],
    subject="Email Subject",
    content="<h1>HTML Content</h1>"
)

With Attachments

with open("document.pdf", "rb") as f:
    file_data = f.read()

result = client.email.send_email(
    from_address="company@email.com",
    recipients=["customer@email.com"],
    subject="Important Document",
    content="Please find the document attached.",
    attachments=[
        {
            "content": file_data,
            "filename": "document.pdf",
            "content_type": "application/pdf"
        }
    ]
)

With CC and BCC

result = client.email.send_email(
    from_address="company@email.com",
    recipients=["main@email.com"],
    subject="Meeting",
    content="Email content",
    cc=["copy@email.com"],
    bcc=["hidden-copy@email.com"],
    reply_to="reply-here@email.com"
)

With Template

result = client.email.send_email_with_template(
    template_id="template-123",
    variables={
        "name": "John Doe",
        "company": "Acme Inc"
    },
    from_address="sender@example.com",
    recipients=["recipient@example.com"]
)

👥 Contacts Module

Create Contact

contact = client.contacts.create(
    email="new@email.com",
    first_name="Jane",
    last_name="Doe",
    audience_id="audience-123",
    tags=["customer", "newsletter"]
)

List Contacts

result = client.contacts.list(
    audience_id="audience-123",
    status="subscribed",
    page=1,
    limit=50
)

for contact in result["contacts"]:
    print(f"{contact['email']}: {contact['first_name']}")

Update Contact

updated = client.contacts.update(
    contact_id="contact-456",
    first_name="Jane Marie",
    tags=["customer", "vip"]
)

📊 Audiences Module

Create Audience

audience = client.audiences.create(
    name="Main Newsletter",
    description="Main subscriber list"
)

List Audiences

result = client.audiences.list(page=1, limit=10)

for audience in result["audiences"]:
    print(f"{audience['name']}: {audience['count']} contacts")

Get Statistics

stats = client.audiences.get_stats("audience-123")
print(f"Total: {stats['total']}")
print(f"Subscribed: {stats['subscribed']}")

⚙️ Configuration

from metigan import MetiganClient

client = MetiganClient(
    api_key="your-api-key",
    timeout=30,          # Optional, defaults to 30 seconds
    retry_count=3,       # Optional, defaults to 3
    retry_delay=2,       # Optional, defaults to 2 seconds
    debug=False          # Optional, defaults to False
)

🔒 Error Handling

from metigan import MetiganClient, ApiError, ValidationError

try:
    result = client.email.send_email(options)
except ValidationError as e:
    print(f"Validation Error: {e.message}")
    if e.field:
        print(f"Field: {e.field}")
except ApiError as e:
    print(f"API Error: {e.status_code} - {e.message}")
except Exception as e:
    print(f"Unknown error: {e}")

📝 Examples

See the examples directory for more complete examples.

📄 License

MIT © Metigan

🔗 Links

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

metigan-1.0.3.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

metigan-1.0.3-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file metigan-1.0.3.tar.gz.

File metadata

  • Download URL: metigan-1.0.3.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for metigan-1.0.3.tar.gz
Algorithm Hash digest
SHA256 495f1c177d5e2e9e25451ce890c736268d95534f9d957bdae383412c8836e5aa
MD5 7e0556e91a78b7bbd1f6848830b132ad
BLAKE2b-256 1f9f5f7ed04fc1cfa0ab40bb3a2eb4fa43b47e690efe0c6ed607bc52b47c2c3f

See more details on using hashes here.

File details

Details for the file metigan-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: metigan-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for metigan-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7e22d22bc64b6ce7275092d9fea6fac4e2afabe86dafaef78261095fe54683d3
MD5 69f42e38aaa7a0d0ab14e491df7801f1
BLAKE2b-256 9c0e7e0a47745ea75f76ef57d4f3c0a288a37b8d53a7624948257df4889e2af3

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