Get started by installing the SDK:

pip install posto-sdk

The SDK offers two main classes:

  1. PostoSDK: The core class providing direct API access with basic functionality.

  2. SocialMediaManager: An all-in-one solution that inherits all PostoSDK functionality while adding convenience methods.

Important: You only need to initialize SocialMediaManager to access all SDK features. There's no need to initialize both classes separately.

# All-in-one approach (recommended)
from posto_sdk import SocialMediaManager

# Initialize once and get access to all functionality
manager = SocialMediaManager()

# Use both basic PostoSDK methods and enhanced SocialMediaManager methods
channels = manager.get_active_channels()  # PostoSDK method
manager.post_to("instagram", "Hello world!")  # SocialMediaManager method

If you only need the core functionality, you can use PostoSDK directly:

from posto_sdk import PostoSDK

# Basic initialization
posto = PostoSDK.from_token(token="your_base64_encoded_token

Posting a Message

The core method for posting is post(). It accepts a message along with several optional keyword parameters that control target channels, scheduling, media attachments, and network settings.

Parameters

  • message (str) The text content you want to post.

  • to (int, str, or list) Specifies the channel(s) by which to post. Pass the channel ID (int) or name of the channel (str) or a list of them.

    • Example: to=2, to="News Feed", or to=[2, "Blog"].

  • when (datetime, str, or int, optional) Define when to post your message:

    • Immediate posting: Set to "now" or omit this parameter.

    • Relative time string: Use a string like "30m" for 30 minutes, "1h" for 1 hour, or "2d" for 2 days from now.

    • Human-readable string: Use strings like "tomorrow at 3pm" or "next Monday at noon".

    • Specific datetime: Pass a datetime object or a Unix timestamp (int).

  • media (str or list, optional) Path(s) or URL(s) to media files (images, videos) to attach. Accepts a single file (string) or a list of files.

    • The SDK will automatically download media from URLs if provided.

  • settings (dict, optional) Custom network settings to override the defaults for each channel's post. See the Custom Network Settings section for more details.

  • use_local_time (bool, default=True) Whether to interpret datetime strings in your local timezone. Set to False to use UTC.

Immediate Post

Post a message immediately to a single channel.

Scheduled Post (Relative Time)

Schedule a post to be published in, for example, 1 hour.

Scheduled Post (Human-Readable Time)

Schedule a post using natural language time expressions.

Scheduled Post (Specific DateTime)

Schedule the post for a specific future datetime.

Post with Media Attachment

You can easily attach media (local file path or URL) along with your message.

For multiple media attachments, pass a list:

Custom Network Settings

Override default network settings (if necessary) by passing a settings dictionary. The keys in this dictionary depend on the specific network, but common options include toggles for attaching links, cutting post text, etc.

Channel Management

The SDK provides several methods to query and manage your social media channels.

List All Channels

Get a Channel by ID

Find Channels by Name

Get Channels by Network Type

Get Active Channels Only

Get Available Network Types

Refresh Channel List

Schedule Management

The SDK provides a schedules property that gives you access to the ScheduleManager for managing scheduled posts.

List Schedules

Retry Failed Schedules

Delete Schedules

Network Settings Management

The SDK allows you to retrieve and manage network-specific settings.

Get Available Networks

Get Network Settings

Save Network Settings

Settings Profiles

You can save and load settings profiles to reuse configurations across multiple posts.

Error Handling

The SDK raises custom exceptions to help you manage errors:

  • MediaUploadError: Raised when media uploading fails.

  • ChannelError: Raised for channel-related issues.

  • PostingError: Raised if the post creation fails.

Always handle or log errors when calling post():

Understanding PostResult

The post() method returns a PostResult object with these properties:

  • success: Boolean indicating if the post was successful

  • schedule_group_id: ID of the schedule group (if successful)

  • error_message: Error message (if failed)

  • media_ids: List of uploaded media IDs

Complete Example

Below is a complete example that combines several of the features described above.

SocialMediaManager - All-in-One Solution

This guide covers the basics of using the SocialMediaManager class, which extends the base PostoSDK to simplify managing social media channels. You will learn how to initialize the SDK, set default posting options, post messages, schedule campaigns, and manage custom post styles.

Important Note on SocialMediaManager

SocialMediaManager is an all-in-one solution that inherits all functionality from PostoSDK. When you initialize SocialMediaManager, you don't need to separately initialize PostoSDK - you get access to all PostoSDK methods plus the additional convenience methods provided by SocialMediaManager.

1. Installation

Make sure you have installed the SDK and its dependencies. Then, you can import the SocialMediaManager in your project:

2. Initialization

Initialize the SocialMediaManager with your credentials. The credentials are used to create an authentication token.

3. Setting Default Post Settings

You can globally define post settings that apply to all channels of a network or to a specific channel.

3.1. Set Network Defaults

Use set_network_defaults to define defaults for a particular network (such as Twitter, Facebook, TikTok, etc.). These settings will apply to all channels within that network.

3.2. Set Channel Defaults

For channel-specific settings, use set_channel_defaults. If you pass a channel name, the method will find the corresponding channel ID.

3.3. Clear Default Settings

You can clear default settings when needed:

4. Posting Messages

There are several ways to post messages using the SDK. Choose the one that best fits your needs.

4.1. Quick Post

Post a message immediately to all active channels.

Method Signature:

  • message: The post content.

  • image: A path (or URL) to an image file (if any).

  • style: Predefined style name (e.g., "announcement", "blog", or "product").

  • settings: A dictionary with network-specific overrides.

Example:

4.2. Post to Specific Platforms

Use post_to to send a post to selected platforms. This method supports scheduling with the when parameter as well.

Method Signature:

  • platforms: A single platform (e.g., "twitter") or a list of platforms (e.g., ["facebook", "instagram"]).

  • message: The text to post.

  • image: Optional image path or URL.

  • when: Schedule the post (e.g., "tomorrow", "tonight", "30m", "1h", "2d").

  • style: Predefined style (as in quick_post).

  • settings: A dictionary of custom settings for refining the post.

Example:

4.3. Scheduling a Post

Schedule a post for a later time using the schedule_post method.

Method Signature:

  • when: Can be friendly strings like "tomorrow" or "tonight", or a relative time like "30m", "1h", or "2d".

Example:

4.4. Creating a Campaign

A campaign is a series of posts scheduled over time.

Method Signature:

  • messages: List of messages.

  • platforms: List of target platforms. If omitted, the campaign is posted to all available networks.

  • images: Optional list of image paths/URLs for each post.

  • start_time: When the campaign should start (e.g., "tomorrow" or "tonight").

  • hours_between_posts: Interval between each post (default is 24 hours).

  • style: Predefined style.

  • settings: Network-specific custom settings.

Example:

4.5. Creating a Quick Campaign

For a faster setup with sensible defaults, you can use create_quick_campaign.

Method Signature:

  • interval: Time between posts given as "1d", "1h", etc.

  • start_time: When the campaign should begin (e.g., "tomorrow").

Example:

5. Customizing Post Styles

You can save and reuse custom post styles, which is very helpful if you frequently use specific formatting across different platforms.

5.1. Saving a Style

Method Signature:

  • name: A unique name for your style.

  • settings: A dictionary mapping social network identifiers (e.g., "twitter", "facebook") to their settings.

Example:

5.2. Retrieving and Listing Styles

List all available styles:

6. Managing Channels & Defaults

Access your channels and review or clear default settings as needed.

6.1. Getting Channels

6.2. Viewing & Clearing Defaults

7. Deleting Scheduled Posts

Manage your scheduled posts by deleting unwanted schedules.

7.1. Delete All Schedules with Filters

7.2. Delete Specific Scheduled Posts

8. Complete Example

Below is a simple script that brings many of these features together:

SocialMediaManager Quick Reference

Here's a quick reference of all available methods in SocialMediaManager:

Posting Methods

  • quick_post(message, image=None, style=None, settings=None) - Post to all active channels

  • post_to(platforms, message, image=None, when=None, style=None, settings=None) - Post to specific platforms

  • schedule_post(message, when, image=None, platforms=None, style=None, settings=None) - Schedule a post

  • create_campaign(messages, platforms=None, images=None, start_time=None, hours_between_posts=24, style=None, settings=None) - Create a campaign

  • create_quick_campaign(messages, interval="1d", start_time=None) - Create a simple campaign

Style Management

  • save_style(name, settings) - Save a custom style

  • get_style(name) - Get a saved style

  • list_styles() - List all saved styles

Channel Management

  • get_channels(platform=None) - Get channels, optionally filtered by platform

  • find_channel(name) - Find a channel by name (case-insensitive partial match)

Default Settings

  • set_network_defaults(network, settings) - Set defaults for a network

  • set_channel_defaults(channel_id, settings) - Set defaults for a channel

  • get_network_defaults(network) - Get defaults for a network

  • get_channel_defaults(channel_id) - Get defaults for a channel

  • clear_defaults(network=None, channel_id=None) - Clear defaults

Schedule Management

  • delete_all_schedules(exclude_ids=None, platforms=None, statuses=None) - Delete schedules with filters

  • delete_schedules(schedule_ids) - Delete specific schedules

Last updated 21 hours ago

Last updated