Skip to main content

A convenient way to harvest Reels data without breaking a sweat—or Instagram's TOS

Project description

PyPI version Build Code Tests Coverage

ReelScraper

Scrape Instagram Reels data with ease—be it a single account or many in parallel—using Python, threading, robust logging, and optional database support.

InstallationUsageClassesDocumentationContributingLicenseAcknowledgmentsDisclaimer


💻 Installation

Requires Python 3.9+. Install directly from PyPI:

pip install reelscraper

Or clone from GitHub:

git clone https://github.com/andreaaazo/reelscraper.git
cd reelscraper
python -m pip install .

🚀 Usage

ReelScraper supports detailed logging and optional persistence via a database. You can either scrape a single Instagram account or handle multiple accounts concurrently.

1. Single-Account Scraping

Use ReelScraper to fetch Reels for a single account. Optionally pass a LoggerManager for retry logs and progress tracking.

from reelscraper import ReelScraper
from reelscraper.utils import LoggerManager

# Optional logger setup
logger = LoggerManager()

# Initialize scraper with a 30-second timeout, no proxy, and logging
scraper = ReelScraper(timeout=30, proxy=None, logger_manager=logger)

# Fetch up to 10 reels for "someaccount"
reels_data = scraper.get_user_reels("someaccount", max_posts=10)
for reel in reels_data:
    print(reel)

2. Multi-Account Concurrency & Database Storage

Use ReelMultiScraper to process many accounts concurrently. Configure logging (LoggerManager) and database persistence (DBManager) if desired.

from reelscraper import ReelScraper, ReelMultiScraper
from reelscraper.utils import LoggerManager
from reelscraper.utils.database import DBManager

# Configure logger and optional DB manager
logger = LoggerManager()
db_manager = DBManager(db_url="sqlite:///myreels.db")

# Create a single scraper instance
single_scraper = ReelScraper(timeout=30, proxy=None, logger_manager=logger)

# MultiScraper for concurrency, database integration, and auto-logging
multi_scraper = ReelMultiScraper(
    single_scraper,
    max_workers=5,
    db_manager=db_manager,
)

# File contains one username per line, e.g.:
#   user1
#   user2
accounts_file_path = "accounts.txt"

# Scrape accounts concurrently
# If DBManager is provided, results are stored in DB, and this method returns None
all_reels = multi_scraper.scrape_accounts(
    accounts_file=accounts_file_path,
    max_posts_per_profile=20,
    max_retires_per_profile=10
)

if all_reels is not None:
    print(f"Total reels scraped: {len(all_reels)}")
else:
    print("All reels have been stored in the database.")

Note: If DBManager is set, scraped reels are saved to the database instead of being returned.


🏗 Classes

ReelScraper

  • Purpose:
    Fetches Instagram Reels for a single user session.
  • Key Components:
    • InstagramAPI: Manages HTTP requests and proxy usage.
    • Extractor: Structures raw reel data.
    • LoggerManager (optional): Logs retries and status events.
  • Key Method:
    • get_user_reels(username, max_posts=50, max_retries=10): Retrieves reels, handling pagination and retries.

ReelMultiScraper

  • Purpose:
    Scrapes multiple accounts in parallel, powered by a single ReelScraper instance.
  • Key Components:
    • ThreadPoolExecutor: Enables concurrent scraping.
    • AccountManager: Reads accounts from a local file.
    • LoggerManager (optional): Captures multi-account events.
    • DBManager (optional): Saves aggregated results to a database.
  • Key Method:
    • scrape_accounts(accounts_file, max_posts_per_profile, max_retires_per_profile): Concurrently processes all accounts found in the file, optionally storing results in a DB.

📄 Documentation

Find full usage details in the DOCS.md file.


🤝 Contributing

We welcome PRs that enhance features, fix bugs, or improve docs.

  1. Fork the repo.
  2. Create a new branch.
  3. Commit code changes (add tests where possible).
  4. Open a pull request.

Your contributions are appreciated—happy coding!


📄 License

Licensed under the MIT License. Feel free to modify and distribute, but please be mindful of best practices and ethical scraping.


🙏 Acknowledgments

  • Python Community: For making concurrency and requests straightforward to implement.
  • Instagram: For providing reel content that inspires creativity.
  • Beverages: For fueling late-night debugging and coding sessions.

⚠ Disclaimer

This software is for personal and educational purposes only. Use it in accordance with Instagram’s Terms of Service. We do not promote or condone large-scale commercial scraping or any violation of privacy/IP rights.


Enjoy scraping, and may your concurrency be swift!

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

reelscraper-2.2.1.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

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

reelscraper-2.2.1-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file reelscraper-2.2.1.tar.gz.

File metadata

  • Download URL: reelscraper-2.2.1.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for reelscraper-2.2.1.tar.gz
Algorithm Hash digest
SHA256 54b85c2b6b9b0e910146536609c2d4411038f2a58e38f6f99c772e605107e4b0
MD5 d9e51472b85e0fa53494e658cec0bdf2
BLAKE2b-256 03d9c5fd7d7e2c98c45560d2da7813234b69333ea3f692f2520ca159fc698def

See more details on using hashes here.

Provenance

The following attestation bundles were made for reelscraper-2.2.1.tar.gz:

Publisher: pypi-publish.yml on andreaaazo/reelscraper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file reelscraper-2.2.1-py3-none-any.whl.

File metadata

  • Download URL: reelscraper-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for reelscraper-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4a2d1199ad6b95f6920c53e8f10762ef684673ce5db3885c47e9514e648d3773
MD5 f8b7fe5e965d6b28b26ce37e0dfee8fc
BLAKE2b-256 8e50c7ba006ebd05645ffebcee47ac83ef0dbd6bd47741be9a764ca83e6aa9f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for reelscraper-2.2.1-py3-none-any.whl:

Publisher: pypi-publish.yml on andreaaazo/reelscraper

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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