CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-instabot

Instagram bot scripts for promotion and API python wrapper

Pending
Overview
Eval results
Files

bot-automation.mddocs/

Bot Automation

High-level Instagram automation framework with built-in safety features, rate limiting, intelligent filtering, and batch operations. The Bot class provides comprehensive automation capabilities while maintaining account security through configurable limits and smart filtering.

Capabilities

Bot Initialization and Authentication

Initialize and configure the Instagram bot with extensive customization options for safety, rate limiting, and behavior modification.

class Bot:
    def __init__(self,
                 base_path=current_path + "/config/",
                 whitelist_file="whitelist.txt",
                 blacklist_file="blacklist.txt",
                 comments_file="comments.txt",
                 followed_file="followed.txt",
                 unfollowed_file="unfollowed.txt",
                 skipped_file="skipped.txt",
                 friends_file="friends.txt",
                 proxy=None,
                 max_likes_per_day=random.randint(50, 100),
                 max_unlikes_per_day=random.randint(50, 100),
                 max_follows_per_day=random.randint(50, 100),
                 max_unfollows_per_day=random.randint(50, 100),
                 max_comments_per_day=random.randint(50, 100),
                 max_blocks_per_day=random.randint(50, 100),
                 max_unblocks_per_day=random.randint(50, 100),
                 max_likes_to_like=random.randint(50, 100),
                 min_likes_to_like=random.randint(50, 100),
                 max_messages_per_day=random.randint(50, 100),
                 filter_users=False,
                 filter_private_users=False,
                 filter_users_without_profile_photo=False,
                 filter_previously_followed=False,
                 filter_business_accounts=False,
                 filter_verified_accounts=False,
                 max_followers_to_follow=5000,
                 min_followers_to_follow=10,
                 max_following_to_follow=2000,
                 min_following_to_follow=10,
                 max_followers_to_following_ratio=15,
                 max_following_to_followers_ratio=15,
                 min_media_count_to_follow=3,
                 max_following_to_block=2000,
                 like_delay=random.randint(300, 600),
                 unlike_delay=random.randint(300, 600),
                 follow_delay=random.randint(300, 600),
                 unfollow_delay=random.randint(300, 600),
                 comment_delay=random.randint(300, 600),
                 block_delay=random.randint(300, 600),
                 unblock_delay=random.randint(300, 600),
                 message_delay=random.randint(300, 600),
                 stop_words=("shop", "store", "free"),
                 blacklist_hashtags=["#shop", "#store", "#free"],
                 blocked_actions_protection=True,
                 blocked_actions_sleep=True,
                 blocked_actions_sleep_delay=random.randint(600, 1200),
                 verbosity=True,
                 device=None,
                 save_logfile=True,
                 log_filename=None,
                 loglevel_file=logging.DEBUG,
                 loglevel_stream=logging.INFO,
                 log_follow_unfollow=True):
        """
        Initialize Instagram bot with comprehensive configuration options.
        
        Parameters:
        - base_path: Directory for bot configuration files (current_path + "/config/")
        - whitelist_file, blacklist_file, comments_file, followed_file, unfollowed_file, 
          skipped_file, friends_file: Filenames for various user lists and bot state
        - proxy: Proxy server configuration
        - max_*_per_day: Daily limits for actions (random.randint(50, 100))
        - max_likes_to_like, min_likes_to_like: Like count filtering thresholds
        - max_messages_per_day: Daily message limit
        - filter_*: Boolean flags for user filtering (defaults False)
        - max/min_followers/following_to_follow: Follower/following count thresholds
        - max_followers_to_following_ratio, max_following_to_followers_ratio: Ratio limits
        - min_media_count_to_follow: Minimum media posts required
        - max_following_to_block: Maximum following count for blocking
        - *_delay: Action delays in seconds (random.randint(300, 600) or (600, 1200))
        - stop_words: Tuple of words to avoid in usernames/bios
        - blacklist_hashtags: List of hashtags to avoid
        - blocked_actions_protection, blocked_actions_sleep: Safety features
        - verbosity: Enable verbose logging
        - device, save_logfile, log_filename, loglevel_*: API configuration
        - log_follow_unfollow: Log follow/unfollow actions
        """

    def login(self, username=None, password=None, **args):
        """
        Login to Instagram with bot configuration and safety checks.
        
        Parameters:
        - username: Instagram username
        - password: Instagram password
        - **args: Additional login parameters passed to API
        
        Returns:
        bool: True if login successful, False otherwise
        """

    def logout(self):
        """
        Logout from Instagram and display session statistics.
        
        Prints comprehensive statistics about bot actions performed
        during the session including likes, follows, comments, etc.
        """

Content Upload and Management

Upload and manage photos and videos with automatic filtering and safety checks.

def upload_photo(self, photo, caption=None, upload_id=None, from_video=False, options={}):
    """
    Upload photo to Instagram with bot validation and logging.
    
    Parameters:
    - photo: Path to photo file or photo data
    - caption: Photo caption text
    - upload_id: Optional upload identifier
    - from_video: Whether photo is extracted from video
    - options: Additional upload options
    
    Returns:
    bool: True if upload successful, False otherwise
    """

def upload_video(self, video, caption="", thumbnail=None, options={}):
    """
    Upload video to Instagram with thumbnail and caption.
    
    Parameters:
    - video: Path to video file
    - caption: Video caption text
    - thumbnail: Path to thumbnail image
    - options: Additional upload options
    
    Returns:
    bool: True if upload successful, False otherwise
    """

def download_photo(self, media_id, folder="photos", filename=None, save_description=False):
    """
    Download photo from Instagram by media ID.
    
    Parameters:
    - media_id: Instagram media identifier
    - folder: Download destination folder
    - filename: Custom filename (optional)
    - save_description: Save caption as text file
    
    Returns:
    bool: True if download successful, False otherwise
    """

def download_video(self, media_id, folder="videos", filename=None, save_description=False):
    """
    Download video from Instagram by media ID.
    
    Parameters:
    - media_id: Instagram media identifier
    - folder: Download destination folder
    - filename: Custom filename (optional)
    - save_description: Save caption as text file
    
    Returns:
    bool: True if download successful, False otherwise
    """

Automated Engagement Actions

Perform automated likes, follows, and other engagement actions with intelligent targeting and safety limits.

def like_timeline(self, amount=None):
    """
    Automatically like posts from timeline feed.
    
    Parameters:
    - amount: Number of posts to like (uses bot limits if None)
    
    Returns:
    int: Number of posts successfully liked
    """

def like_user(self, user_id, amount=None, filtration=True):
    """
    Like posts from specific user with filtering and limits.
    
    Parameters:
    - user_id: Target user ID or username
    - amount: Number of posts to like
    - filtration: Apply bot filtering criteria
    
    Returns:
    int: Number of posts successfully liked
    """

def like_hashtag(self, hashtag, amount=None):
    """
    Like posts from hashtag feed with smart filtering.
    
    Parameters:
    - hashtag: Hashtag name (without #)
    - amount: Number of posts to like
    
    Returns:
    int: Number of posts successfully liked
    """

def like_followers(self, user_id, nlikes=None, nfollows=None):
    """
    Like posts from followers of target user.
    
    Parameters:
    - user_id: Target user ID or username
    - nlikes: Number of likes per follower
    - nfollows: Number of followers to process
    
    Returns:
    int: Number of users processed
    """

def follow_followers(self, user_id, nfollows=None):
    """
    Follow followers of target user with filtering.
    
    Parameters:
    - user_id: Target user ID or username
    - nfollows: Number of users to follow
    
    Returns:
    int: Number of users successfully followed
    """

def follow_following(self, user_id, nfollows=None):
    """
    Follow users that target user is following.
    
    Parameters:
    - user_id: Target user ID or username
    - nfollows: Number of users to follow
    
    Returns:
    int: Number of users successfully followed
    """

def unfollow_non_followers(self, n_to_unfollows=None):
    """
    Unfollow users who don't follow back.
    
    Parameters:
    - n_to_unfollows: Number of users to unfollow
    
    Returns:
    int: Number of users successfully unfollowed
    """

def unfollow_everyone(self):
    """
    Unfollow all currently followed users.
    
    Returns:
    int: Number of users successfully unfollowed
    """

Content Discovery and Filtering

Discover and filter content based on sophisticated criteria for targeted automation.

def get_hashtag_medias(self, hashtag, filteration=True):
    """
    Get media posts from hashtag with optional filtering.
    
    Parameters:
    - hashtag: Hashtag name (without #)
    - filteration: Apply bot filtering criteria
    
    Returns:
    list: List of media IDs that passed filtering
    """

def get_user_medias(self, user_id, filteration=True, is_comment=False):
    """
    Get media posts from specific user.
    
    Parameters:
    - user_id: Target user ID or username
    - filteration: Apply bot filtering criteria
    - is_comment: Whether media is for commenting
    
    Returns:
    list: List of media IDs that passed filtering
    """

def get_timeline_medias(self):
    """
    Get media posts from timeline feed.
    
    Returns:
    list: List of media IDs from timeline
    """

def get_popular_medias(self):
    """
    Get popular/trending media posts.
    
    Returns:
    list: List of popular media IDs
    """

def filter_medias(self, media_items, filteration=True, quiet=False, is_comment=False):
    """
    Filter media posts based on bot criteria.
    
    Parameters:
    - media_items: List of media items to filter
    - filteration: Enable filtering
    - quiet: Suppress logging output
    - is_comment: Whether filtering for commenting
    
    Returns:
    list: Filtered list of media items
    """

def check_user(self, user, unfollowing=False):
    """
    Check if user meets bot criteria for interaction.
    
    Parameters:
    - user: User data dictionary or user ID
    - unfollowing: Whether check is for unfollowing action
    
    Returns:
    bool: True if user passes criteria, False otherwise
    """

def check_media(self, media):
    """
    Check if media meets bot criteria for interaction.
    
    Parameters:
    - media: Media data dictionary
    
    Returns:
    bool: True if media passes criteria, False otherwise
    """

User Management and Information

Manage user relationships and retrieve user information with caching and filtering.

def get_user_followers(self, user_id, nfollows=None):
    """
    Get followers of specific user with limits.
    
    Parameters:
    - user_id: Target user ID or username
    - nfollows: Maximum number of followers to retrieve
    
    Returns:
    list: List of follower user IDs
    """

def get_user_following(self, user_id, nfollows=None):
    """
    Get users that specific user is following.
    
    Parameters:
    - user_id: Target user ID or username
    - nfollows: Maximum number of following to retrieve
    
    Returns:
    list: List of following user IDs
    """

def get_user_info(self, user_id, use_cache=True):
    """
    Get detailed user information with caching.
    
    Parameters:
    - user_id: Target user ID or username
    - use_cache: Use cached information if available
    
    Returns:
    dict: User information dictionary
    """

Statistics and Analytics

Track and analyze bot performance with comprehensive statistics and reporting.

def save_user_stats(self, username, path=""):
    """
    Save user statistics to file for analysis.
    
    Parameters:
    - username: Username to save stats for
    - path: Directory path for stats file
    
    Returns:
    bool: True if stats saved successfully
    """

def print_counters(self):
    """
    Print comprehensive statistics about bot actions.
    
    Displays counters for likes, follows, unfollows, comments,
    and other actions performed during the session.
    """

Bot Properties

Access bot state, configuration, and collected data through properties.

@property
def following(self):
    """List of user IDs currently being followed"""

@property 
def followers(self):
    """List of current follower user IDs"""

@property
def blacklist(self):
    """Set of blacklisted user IDs"""

@property
def whitelist(self):
    """Set of whitelisted user IDs"""

@property
def total(self):
    """Dictionary of action counters"""

@property
def blocked_actions(self):
    """Dictionary of blocked action flags"""

Usage Examples

Basic Automation Workflow

from instabot import Bot

# Initialize bot with custom limits
bot = Bot(
    max_likes_per_day=80,
    max_follows_per_day=60,
    filter_private_users=True,
    min_followers_to_follow=100
)

# Login
bot.login(username="your_username", password="your_password")

# Upload content
bot.upload_photo("content/photo1.jpg", caption="Check out this amazing view! #photography #nature")

# Automated engagement
bot.like_hashtag("photography", amount=15)
bot.follow_followers("target_photographer", nfollows=10)

# Content discovery and targeted actions
media_ids = bot.get_hashtag_medias("landscape")
for media_id in media_ids[:5]:
    bot.like(media_id)

# Cleanup actions
bot.unfollow_non_followers(n_to_unfollows=20)

# View statistics and logout
bot.print_counters()
bot.logout()

Advanced Configuration

from instabot import Bot

# Advanced bot configuration
bot = Bot(
    base_path="./my_bot_config/",
    proxy="http://proxy.example.com:8080",
    max_likes_per_day=120,
    max_follows_per_day=80,
    filter_verified_users=False,  # Allow verified users
    max_followers_to_follow=10000,
    min_followers_to_follow=50,
    max_following_to_followers_ratio=1.5,
    min_media_count_to_follow=5
)

bot.login(username="advanced_user", password="secure_password")

# Multi-hashtag strategy
hashtags = ["python", "coding", "programming", "developer"]
for hashtag in hashtags:
    bot.like_hashtag(hashtag, amount=8)
    
# Targeted following with limits
influencers = ["tech_leader1", "python_expert", "coding_guru"]
for influencer in influencers:
    bot.follow_followers(influencer, nfollows=15)

bot.logout()

Install with Tessl CLI

npx tessl i tessl/pypi-instabot

docs

api-access.md

bot-automation.md

file-management.md

index.md

tile.json