Skip to main content
Socialift
Documentation sections
Quickstart

Get started with the Socialift SDK

Socialift is an async Python SDK for Instagram, Facebook, LinkedIn, TikTok and Telegram. To start you need Python 3.11+, pip install socialift and an slk_... license key from the “Tokenlar” (Tokens) section of the dashboard. Put the key in SOCIALIFT_LICENSE_KEY and make a first call: a Telegram bot needs only its BotFather token, while Facebook and Instagram tokens come from OAuth.

Updated:

In short: how do you get started with the Socialift SDK?

Four steps: (1) pip install socialift; (2) socialift.uz/dashboard → “Tokenlar” (Tokens) → “Yangi token” (New token), then “Kalitni ko'rsatish” (Show key); (3) put the key in the SOCIALIFT_LICENSE_KEY environment variable; (4) make a first call. The fastest path is a Telegram bot: just a BotFather token, get_me() and send_message(). Facebook and Instagram need a Meta app and OAuth: login_url() → exchange_code() → pages() → Instagram.via_facebook().

You can also try every method in the dashboard Playground before writing code — see the section below.

What do you need to start?

What do you need to start? — Capability matrix by platform
WhatWhere to get itWhich path
Python 3.11 or newerpython.org or your system package managerAll
License key slk_...Dashboard → “Tokenlar” (Tokens) → “Yangi token” (New token)All
Bot token@BotFather in Telegram → /newbotA: Telegram bot
Meta App ID and App Secretdevelopers.facebook.com → create an appB: Facebook and Instagram
Instagram Business or Creator account linked to a Facebook PageInstagram app settingsB: Instagram

Step 1: install the SDK and configure the key

  1. Install the package

    pip install socialift. The only core dependencies are aiohttp and cryptography. For a live Telegram user account (TelegramAccount, MTProto) run pip install 'socialift[telegram]', which adds Telethon; a Telegram bot does not need it.

  2. Get a license key

    socialift.uz/dashboard → “Tokenlar” (Tokens) → “Yangi token” (New token). The key starts with slk_; copy it with “Kalitni ko'rsatish” (Show key) and “Nusxa” (Copy). The first month is free, with every SDK feature unlocked.

  3. Put the key in an environment variable

    SOCIALIFT_LICENSE_KEY=slk_.... Keep it out of your code — clients read it from the environment. The key is checked before the first request, not at import time.

  4. Name the environment in containers

    In Docker or Kubernetes set a stable value such as SOCIALIFT_INSTANCE_ID=my-app-prod; otherwise every deploy takes a new seat. Details are on the Authentication page.

In the terminal: install and set the key

terminal
python -m pip install socialift
python -m pip install "socialift[telegram]"   # only for TelegramAccount (MTProto)

export SOCIALIFT_LICENSE_KEY="slk_..."
# Windows PowerShell: $env:SOCIALIFT_LICENSE_KEY="slk_..."

python -c 'import socialift; print(socialift.__version__)'

The last command prints the installed version. The license is not checked yet at this point — that happens before the first API request.

Path A: a Telegram bot — first message in minutes

Create a bot with /newbot in @BotFather, put the token in TELEGRAM_BOT_TOKEN and send the bot any message in Telegram — the script picks the chat ID from that message.

bot.py
import asyncio
from socialift import Telegram


async def main():
    async with Telegram.from_env() as bot:        # reads TELEGRAM_BOT_TOKEN
        me = await bot.get_me()
        print("Bot:", me["username"])

        updates = await bot.get_updates(timeout=0)
        messages = [u["message"] for u in updates if "message" in u]
        if not messages:
            print("Send your bot a message in Telegram first")
            return
        chat_id = messages[-1]["chat"]["id"]
        await bot.send_message(chat_id, "Hello! The Socialift SDK works.")


asyncio.run(main())

get_me() is the cheapest way to validate a token: an invalid token raises an ApiError subclass (usually AuthError).

get_updates() does not work while the bot has a webhook set — Telegram delivers updates either by webhook or by polling.

To post to a channel pass "@channel_name" instead of chat_id; the bot must be a channel admin.

Path B: Facebook and Instagram via OAuth

When an Instagram Business or Creator account is linked to a Facebook Page, you get the token through Facebook Login and call Instagram with the Page token.

  1. Create a Meta app

    Create an app at developers.facebook.com and put its App ID and App Secret in FACEBOOK_APP_ID and FACEBOOK_APP_SECRET. See the Meta app setup guide for details.

  2. Register the redirect URI

    Add your callback URL to the Facebook Login settings (for example https://example.uz/auth/facebook/callback). login_url() and exchange_code() must receive exactly the same URL, character for character.

  3. Request permissions

    Reading Pages and the linked Instagram account needs pages_show_list and instagram_basic. With a Facebook Login for Business configuration you pass config_id instead of scopes.

  4. Send the user to the login dialog

    fb.login_url(...) returns the link. Store state in the session and compare it in the callback — the SDK does not store it.

  5. Get the token and Pages in the callback

    exchange_code() swaps the code for a long-lived user token, and pages() returns Pages with their Page tokens and linked Instagram IDs.

login.py
import secrets
from socialift import Facebook

REDIRECT_URI = "https://example.uz/auth/facebook/callback"

fb = Facebook.from_env()              # FACEBOOK_APP_ID, FACEBOOK_APP_SECRET
state = secrets.token_urlsafe(32)     # store it in the session
url = fb.login_url(
    redirect_uri=REDIRECT_URI,
    state=state,
    scopes=["pages_show_list", "instagram_basic"],
)
print(url)

login_url() is synchronous and makes no network call, so it needs no await.

Callback: token, Pages and the Instagram profile

callback.py
import asyncio
import os
from socialift import Facebook, Instagram

REDIRECT_URI = "https://example.uz/auth/facebook/callback"


async def handle_callback(code: str):
    async with Facebook.from_env() as fb:
        user = await fb.exchange_code(code, redirect_uri=REDIRECT_URI)
        pages = await fb.pages(user.access_token)

    async with Instagram.via_facebook(app_secret=os.environ["FACEBOOK_APP_SECRET"]) as ig:
        for page in pages:
            if not page.instagram_id:
                continue
            profile = await ig.profile(page.access_token, ig_user_id=page.instagram_id)
            posts = await ig.media(page.access_token, ig_user_id=page.instagram_id, limit=5)
            print(page.name, "->", profile.username, len(posts), "posts")


asyncio.run(handle_callback(code="the code parameter from the callback URL"))

According to Meta, a long-lived user token generally lasts about 60 days; a Page token obtained from it has no set expiry date but can be invalidated under certain conditions.

The SDK stores nothing: save user.access_token and page.access_token encrypted in your database and keep them out of logs. appsecret_proof is added to every Meta request automatically.

To connect Instagram without a Page, use Instagram(app_id=..., app_secret=...) with Instagram Login — see the Instagram Login setup guide.

Try it without code: the Playground

The dashboard Playground lists 191 methods with docs, a parameter form and Python SDK, cURL and JavaScript samples. Connect an account or bot in “Ulanishlar” (Connections), pick a method in the Playground and press “Yuborish” (Send).

Requests are real: posts get published and messages get sent. Deleting and anything that can spend ad budget asks for an extra confirmation first.

Accounts connected in the dashboard are not passed to the SDK: in your own app you obtain tokens through OAuth as shown above and keep them in your database.

Next steps before production

  • Set a stable SOCIALIFT_INSTANCE_ID in containers — see Authentication.
  • Handle AuthError, PermissionError and RateLimitError separately — see Errors.
  • Verify webhook signatures against the raw body — see Webhooks.
  • Track token expiry with TokenBundle.expires_at and is_expiring().
  • Every method and parameter is listed in the SDK reference pages.

Frequently asked questions

Which Python versions does the Socialift SDK support?

Python 3.11 and newer. The SDK is fully async (built on aiohttp): you call methods with await, and a plain script uses asyncio.run(main()). It behaves the same in FastAPI, background workers or scripts — anywhere asyncio runs.

Does the SDK work without a license key?

Clients that call the platforms do not: with no key found, LicenseRequired is raised before the first request. The key is checked neither at import nor when you create a client, but right before the first request. The first month is free — get the key under “Tokenlar” (Tokens).

Do I need a Meta app or any developer app for a Telegram bot?

No. The Telegram Bot API only needs the token from @BotFather: Telegram(token=...) or Telegram.from_env(). api_id and api_hash are only for a live Telegram user account (TelegramAccount, MTProto).

Can I connect Instagram without a Facebook Page?

Yes, for a professional (Business or Creator) account via Instagram Login: Instagram(app_id=..., app_secret=...), then login_url() and exchange_code(). The Page-based flow uses Instagram.via_facebook(app_secret=...) with a Page token.

Does the SDK store tokens for me?

No. The package persists nothing: tokens, sessions and the database are your application's job. The TokenBundle returned by exchange_code() has access_token, expires_in and expires_at — store them encrypted.

Sources

  1. Telegram Bot API
  2. Meta: Instagram API with Facebook Login — Get started
  3. Meta: Long-lived access tokens

Related pages