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.2.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.2-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: instai-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 b6ffb74b2d39f148ec7117663a36d3f5fd0624f246eb6de98195a36cf2030cbc
MD5 43f83c88dd555f5d51802fd1f204cca9
BLAKE2b-256 79d369eaff88c3b983482270cf370e820f5e2d0e97dd9bec74f2c08480834e17

See more details on using hashes here.

File details

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

File metadata

  • Download URL: instai-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b86d04b302e217d2f8b5a8f5bac3e70591b2b22efc721405a7c04247288cfbf1
MD5 38ec349c699d544e6e4579405facd08a
BLAKE2b-256 e1603dcabde0556e6cbf60d01e94bbfa1baf31557fdf32ed0bc86b8cd7c5de21

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