Python SDK

Overview

Official Python SDK for Late API

Schedule social media posts with a clean, type-safe Python interface.

Installation

pip install late-sdk

Optional extras:

pip install late-sdk[ai]    # With AI content generation (OpenAI)
pip install late-sdk[mcp]   # With Claude Desktop integration

Quick Start

from late import Late, Platform
from datetime import datetime, timedelta

# Initialize client
client = Late(api_key="your_api_key")

# List connected accounts
response = client.accounts.list()
for account in response.accounts:
    print(f"{account.platform}: {account.username}")

# Create a scheduled post
post = client.posts.create(
    content="Hello from Late Python SDK!",
    platforms=[{
        "platform": Platform.TWITTER,
        "accountId": "your_account_id"
    }],
    scheduled_for=datetime.now() + timedelta(hours=1),
)

Type-Safe Enums

The SDK provides enums for better autocomplete and type checking:

from late import Platform, PostStatus, MediaType, CaptionTone, DayOfWeek

# Platforms
Platform.TWITTER, Platform.INSTAGRAM, Platform.LINKEDIN, ...

# Post statuses
PostStatus.DRAFT, PostStatus.SCHEDULED, PostStatus.PUBLISHED, ...

# Media types
MediaType.IMAGE, MediaType.VIDEO, MediaType.GIF, MediaType.DOCUMENT

# AI caption tones
CaptionTone.PROFESSIONAL, CaptionTone.CASUAL, CaptionTone.HUMOROUS, ...

# Queue days
DayOfWeek.MONDAY, DayOfWeek.TUESDAY, ...

Enums work like strings - Platform.TWITTER == "twitter" is True.

Async Support

All methods have async versions prefixed with a:

import asyncio
from late import Late, Platform, PostStatus

async def main():
    async with Late(api_key="your_api_key") as client:
        # Async methods
        accounts = await client.accounts.alist()
        posts = await client.posts.alist(status=PostStatus.SCHEDULED)

        # Create post
        post = await client.posts.acreate(
            content="Async post!",
            platforms=[{"platform": Platform.TWITTER, "accountId": "..."}],
            publish_now=True,
        )

asyncio.run(main())

Resources

Upload Methods

The SDK provides two upload methods depending on file size:

MethodFile SizeRequires
Direct Upload≤ 4 MBAPI Key only
Large File Upload4 MB - 500 MBVercel Token
# Small files (< 4MB) - direct upload
result = client.media.upload("image.jpg")

# Large files - Vercel Blob upload
result = client.media.upload_large(
    "large_video.mp4",
    vercel_token="vercel_blob_rw_xxx"
)

See the Media documentation for details.

Client Configuration

client = Late(
    api_key="your_api_key",
    timeout=30.0,       # Request timeout in seconds
    max_retries=3,      # Retry failed requests
)

Error Handling

from late.client.exceptions import (
    LateAPIError,
    LateAuthenticationError,
    LateRateLimitError,
    LateNotFoundError,
)

try:
    post = client.posts.get("invalid_id")
except LateNotFoundError:
    print("Post not found")
except LateAuthenticationError:
    print("Invalid API key")
except LateRateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except LateAPIError as e:
    print(f"API error: {e.message}")