Skip to main content

Cakemail Next-gen API client

Project description

Install

Install the cakemail package using pip

pip install cakemail

Usage

Create an object from the CakemailApi class with your Cakemail username and password. The object will take care of all authorization mechanisms automatically.

import cakemail

api = cakemail.Api(username='your@email.com', password='somepassword')

Call one of the API operations (refer to the online documentation)

my_account = api.account.get_self()

API operations

API operations accept the OpenAPI models as well as python dictionaries.

from cakemail.models import CreateSender

sender = api.sender.create(
    create_sender=CreateSender(
        name='My Sender',
        email='someone@gmail.com'
    )
)
sender = api.sender.create(
    create_sender={
        'name': 'My Sender',
        'email': 'someone@gmail.com'    
    }
)

Operation Examples

Create a Sender

from cakemail.models import CreateSender, ConfirmSender

sender = api.sender.create(
    CreateSender(name='My Sender', email='someone@gmail.com')
)

Look for a confirmation email in your inbox; click to the link to activate the sender.

Create a Contact List

from cakemail.models import List, Sender

my_new_list = api.list.create(
    list=List(
        name='my new list',
        default_sender=Sender(id=sender.id)
    )
)

Send a transactional email

from cakemail.models import Email, EmailContent

# expressed as OpenAPI models
api.transactional_email.send(
    email=Email(
        email='destination@gmail.com',
        sender=sender,
        content=EmailContent(
            subject='Subject line',
            text='Email body',
            encoding='utf-8'
        )
    )
)

# expressed as a dictionary
api.transactional_email.send(
    email={
        'email': 'destination@gmail.com',
        'sender': sender,
        'content': {
            'subject': 'Subject line',
            'text': 'Email body',
            'encoding': 'utf-8' 
        }
    }
)

Accessing data

The CakemailAPI always return its data under the data object. For simplicity, the resource data is accessible from the returned response directly:

my_user = api.user.get_self()

print(f'id: {my_user.id}, email: {my_user.email}')

Iterate through lists

Some methods return a list of resources on which you can iterate directly:

campaigns = api.campaign.list()
for campaign in campaigns:
    html = api.campaign.render(campaign_id=campaign.id).html
    print(f'id: {campaign.id}, name: {campaign.name}, html: {html}')

Pagination

Pagination is stored in the pagination property of all methods returning a list of resources:

campaigns = api.campaign.list(with_count=True)

print(f"""
  page: {campaigns.pagination.page},
  per_page: {campaigns.pagination.per_page},
  count: {campaigns.pagination.count}
  """)

Dictionary representation

The API methods return response objects; if you prefer to work with a python dict representation, use the to_dict method:

campaign_dict = api.campaign.get(campaign_id=123).to_dict()

for campaign in api.campaign.list():
    print(campaign.to_dict())

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

cakemail-1.12.14.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

cakemail-1.12.14-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file cakemail-1.12.14.tar.gz.

File metadata

  • Download URL: cakemail-1.12.14.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for cakemail-1.12.14.tar.gz
Algorithm Hash digest
SHA256 f3b141fcea0c9ba21aef89641af36f96863ea7b6d9664f9444a24faaad16787f
MD5 350c1527df070a13467bb8f66a83ed83
BLAKE2b-256 ce9b3df5cdced2b12d6800279ed5797d745904752ba7092d93f2ede3447552dc

See more details on using hashes here.

File details

Details for the file cakemail-1.12.14-py3-none-any.whl.

File metadata

  • Download URL: cakemail-1.12.14-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for cakemail-1.12.14-py3-none-any.whl
Algorithm Hash digest
SHA256 44d97d5f05268ed7c36ef0c0b83449469724a129e44d8c9cbf4ca7b110a158d2
MD5 b1fe75b24711873575f9dd36f54879d6
BLAKE2b-256 f888696c35275cdc8b579538b28b489db6310bd74964a11be56024644a4fe502

See more details on using hashes here.

Supported by

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