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.2.tar.gz (34.2 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.2-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: reelscraper-2.2.2.tar.gz
  • Upload date:
  • Size: 34.2 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.2.tar.gz
Algorithm Hash digest
SHA256 15e9410a88908e753bc7e832919c90f81ac975285476fc51155ba855bce04783
MD5 dbc0776ab2f5592b1c7a642d3962e0a0
BLAKE2b-256 63adb1d6bc0a7c96218f33a7c89d74471ce72e4dcf5d64b08880e11dc42ecd29

See more details on using hashes here.

Provenance

The following attestation bundles were made for reelscraper-2.2.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: reelscraper-2.2.2-py3-none-any.whl
  • Upload date:
  • Size: 19.1 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 27655d843a89549caff089e83bba3b6808dd8579d55fc2c8f984ee9c96cbd0d0
MD5 0fb02bd1eb6b4973834436c7e8588bd9
BLAKE2b-256 b7ef9f17d164c183da2e5f593ebe44ead05ed23a1a36f49f770f46f3299c4dd0

See more details on using hashes here.

Provenance

The following attestation bundles were made for reelscraper-2.2.2-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