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.1.tar.gz (10.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.1-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: instai-0.1.1.tar.gz
  • Upload date:
  • Size: 10.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.1.tar.gz
Algorithm Hash digest
SHA256 8f6f3a4c3dd2a4516ca43cd22785bddf924cc7c44d03b2e42f20c0e3aa878ec3
MD5 4007e2b0d548698ac0c35bf57250497a
BLAKE2b-256 2029f106ee3a4350293301cd5617d167daa447709f110a79472b535ccf25e20b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: instai-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 21.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5341b0393ffb8ce47e98465fb477bfaff76e81a4906286042417e14041f29f03
MD5 90e4977061355db72e3226a29bf65938
BLAKE2b-256 bc80930859be9cf484e1b9bdc29fcc3be84f32271696fc04cdf2b1664ef4bd82

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