Skip to main content

Instagram bot framework

Project description

instai

Python Instagram Graph API

Modern asynchronous framework for building Instagram bots with Python.

Create Instagram automation bots with handlers, filters, FSM, dependency injection and async support.


✨ Features

  • ⚡ Fully asynchronous architecture
  • 🧩 Event-based handlers
  • 🔍 Custom filters
  • 💉 Dependency injection system
  • 🧠 FSM (Finite State Machine) support
  • 🗄 Redis storage support
  • 📦 Message and callback event handling
  • 🖼 Rich messages with cards and buttons
  • 🔌 Webhook-based architecture
  • 🐍 Python 3.12+ support

📦 Installation

Install from PyPI:

pip install -U instai

Or install from source:

git clone https://github.com/zerowkaPy/instai
cd instai

pip install .

🚀 Quick start

Example of a simple Instagram bot:

from fastapi import FastAPI, Request

from instai import Instai, Dispatcher, Message, TextFilter, StateFilter
from instai.fsm import FSMContext

bot = Instai(
    access_token="YOUR_ACCESS_TOKEN",
    ig_id="YOUR_INSTAGRAM_ID")

dp = Dispatcher(bot)

@dp.message(TextFilter("hello"))
async def hello(msg: Message, fsm: FSMContext):
    await fsm.set_state("name")
    await msg.send_message("Type your name")

@dp.message(StateFilter("name"))
async def answer(msg: Message, fsm: FSMContext):
    await fsm.clear()
    await msg.send_message(f"Hello, {msg.text}!")


router = FastAPI()

@router.post("/webhook")
async def webhook(request: Request):
    webhook = await request.json()
    await dp.feed_update(webhook)

🎯 Handlers

Instai uses an event-based handler system.

Example:

from instai import Message

@dp.message()
async def echo(msg: Message):
    await msg.send_message(msg.text)

You can use filters, for example filter that executes handler if the text of user message is "I like Python!":

@dp.message(TextFilter("I like Python!"))
async def hello(msg: Message):
    await msg.send_message("I like it too!")

🔘 Buttons

Create interactive buttons:

from instai import Callback, InlineButton, CallbackFilter

buttons = [
    InlineButton(
        text="Menu 📲",
        payload="menu"
        )
    ]

@dp.callback(CallbackFilter(payload="menu"))
async def go_to_menu(cb: Callback):
    await cb.send_buttons("Go to menu:", buttons)

🃏 Cards

Send rich card messages:

from instai.types import Card


cards = [
    Card(
        title="Nike Air Force 1",
        subtitle="price: 100$",
        image_url="https://example.com/nike-af1.png"
    )
]

@dp.message()
async def shoes(msg: Message):
    await msg.send_cards(cards)

🧠 FSM

Store user states and create conversations

FSM storage can use the default in-memory storage or Redis:

from instai.fsm import RedisStorage

RedisStorage(url="redis://localhost:6379/0")

⚙️ Requirements

Python >= 3.12

Instagram Professional Account

Instagram Graph API access token

Webhook server. For example: FastAPI(as above), aiohttp, Django etc.

📌 Project status

🚧 Currently under active development.

Planned features:

  • More Instagram API methods

  • Better documentation

  • Middleware system

  • Testing suite

🤝 Contributing

Contributions are welcome!

Steps:

  1. Fork the repository

  2. Create a new branch

git checkout -b feature/new-feature
  1. Commit changes
git commit -m "Add new feature"
  1. Push branch
git push origin feature/new-feature
  1. Open Pull Request

📄 License

MIT License

Author

Created by zerowkaPy

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

instai-0.1.3.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

instai-0.1.3-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

Details for the file instai-0.1.3.tar.gz.

File metadata

  • Download URL: instai-0.1.3.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for instai-0.1.3.tar.gz
Algorithm Hash digest
SHA256 fb1aa98f52ce85d609a28db407eb28b78a71a741720d2333a8e7985d95f5faa6
MD5 554c9036d1d8c6d950edc119b6a13ba0
BLAKE2b-256 d4686e6190c5b9e16f824c7f9087bb264d9541c7f54773d0a17778d1f910a732

See more details on using hashes here.

File details

Details for the file instai-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: instai-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 27.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for instai-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2ac787be425973d97a746984da1b58332f3c195af533af72a8d8ad82bd26182c
MD5 2b74b4a67abbeeb067f807aae52fdf83
BLAKE2b-256 93da8e77acca89127bdcb2ad095424ecb06fd855d876fefde39327a552e5dff3

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