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.4.tar.gz (13.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.4-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: instai-0.1.4.tar.gz
  • Upload date:
  • Size: 13.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.4.tar.gz
Algorithm Hash digest
SHA256 2b3320a433fb7b18734e139767e345958752f107feb0bb49025fbf67af9de200
MD5 f9e7d109f4ac01721434d4e1082bfdee
BLAKE2b-256 3d92fca65d6b1845c050ea0616e245c34d1671fa1d74b93333963f5abddf05af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: instai-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 29.4 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 25ee5ce7258cd8b360a63a37100286f730b7536f0c23ece1ba47996ce6787c7d
MD5 a446e8c453ab241a6fbacc60f8437bb2
BLAKE2b-256 6b74f1149183e3af19d0d48b1c60608604b5f6c4bd800828222184e0efd3ec24

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