Skip to main content
Loss of provenance

A previous release had provenance metadata, but this release does not. View details.

herascrape: Instagram API client for Python

herascrape is the official Python client for herascrape, a hosted Instagram scraper API. It reads Instagram's private API for you and hands back Instagram's own JSON: profiles, followers, posts, reels, comments, hashtags, locations, audio, stories and search. You do not manage the accounts, devices or proxies.

from herascrape import Client

client = Client(api_key="hs_live_xxxxxxxx")

user = client.user_by_username(username="instagram")
print(user["username"], user["follower_count"])

for follower in client.iter_user_followers(user["pk"], max_items=100):
    print(follower["username"])
  • 37 endpoints, one method each, plus lazy iter_* paginators for the lists.
  • Sync (Client) and async (AsyncClient) with the same surface.
  • Typed exception hierarchy: NotFoundError, PrivateAccountError, RateLimitError and the rest.
  • Retries with backoff, Retry-After handling and a client-side rate limiter.
  • Typed package (py.typed), Python 3.10+, one dependency: httpx.

Documentation: herascrape.com/docs for the API, herascrape.readthedocs.io for this library's reference.

Install

pip install herascrape

Authentication

Create a key in the dashboard; the client sends it in the x-api-key header. Pass it to the constructor:

from herascrape import Client

client = Client(api_key="hs_live_xxxxxxxx")

Or leave it out and the client reads HERASCRAPE_API_KEY from the environment. With no key in either place, constructing a client raises AuthenticationError. Keep keys out of source control.

Billing is per successful call, and failed calls are not billed. See pricing.

Usage

Every method returns the response data as a plain dict, exactly as Instagram sent it. Check an endpoint's What comes back section in the docs before mapping fields.

from herascrape import Client

client = Client()

# Profiles: look a username up once, then use the numeric pk.
user = client.user_by_username(username="instagram")
page = client.user_followers(user["pk"])
print(len(page["items"]), page["has_more"], page["next_cursor"])

# Pagination: iter_* walks the pages lazily.
for reel in client.iter_user_reels(user["pk"], max_items=50):
    print(reel["code"])

# Search: session UUIDs are generated for you.
for hit in client.search_users(query="nike")["items"]:
    print(hit["pk"], hit["username"])

# Posts take a pk or a shortcode.
post = client.post("B4XpqViUFUI")
print(post["like_count"], post["comment_count"])

# Convert between a media pk and its shortcode.
print(client.resolve_media(code="B4XpqViUFUI"))

List responses carry items, next_cursor and has_more. post_comments and user_posts keep Instagram's own paging shape, so page those by hand; see the docs.

Async

import asyncio

from herascrape import AsyncClient


async def main() -> None:
    async with AsyncClient() as client:
        user = await client.user_by_username(username="instagram")
        async for follower in client.iter_user_followers(
            user["pk"], max_items=100
        ):
            print(follower["username"])


asyncio.run(main())

Errors

Every exception inherits from HerascrapeError. API errors are HerascrapeAPIError subclasses carrying status_code, error_code, detail and request_id.

from herascrape import Client, PrivateAccountError, ProfileNotFoundError

client = Client()

try:
    followers = client.user_followers("25025320")
except PrivateAccountError:
    print("private account")
except ProfileNotFoundError:
    print("no such profile")
Exception When
BadRequestError 400. InvalidCursorError and InvalidParameterError are subclasses.
AuthenticationError 401. Missing or invalid key.
ForbiddenError 403. PrivateAccountError is the private-profile case.
NotFoundError 404. ProfileNotFoundError is the unknown-profile case.
ValidationError 422. Per-field messages in field_errors.
RateLimitError 429. Seconds to wait in retry_after, when sent.
ServerError 5xx. InternalError, UpstreamError and ServiceUnavailableError are subclasses.
HerascrapeTransportError No response: connection failure or timeout.

Retries and rate limiting

The client retries connection errors and timeouts, 429, 502, 503 and invalid_cursor up to max_retries times (default 3), backing off from 0.5 s to 8 s with jitter. A 429 with a Retry-After header waits that long, capped at 300 s. It also throttles requests on the client with a token bucket that defaults to 50 requests per second. Match it to your key's limit:

from herascrape import Client, RateLimit

client = Client(rate_limit=RateLimit(rate=10, period="s"))
client = Client(rate_limit=None)  # no client-side limit

Other constructor options: timeout (seconds, default 10), max_retries, and base_url (default https://api.herascrape.com).

Endpoints

All 37 endpoints are GETs. The full table with paths is in the repository README.

Group Methods
Users user_by_username, user, user_followers, user_following, user_posts, user_reels, user_tagged, user_stories, user_highlights, user_reposts, user_about
Posts and comments post, post_comments, post_likers, comment_replies, comment_likers
Search search_users, search_hashtags, search_audio, search_top, search_places
Hashtags hashtag, hashtag_top, hashtag_recent, hashtag_reels
Locations location, location_top, location_recent
Audio audio_trending, audio, audio_medias
Stories and highlights highlight, story
Utility resolve_media, oembed, balance, health

Coming from HikerAPI? The migration guide maps each path to its herascrape equivalent.

Disclaimer

herascrape is not affiliated with, authorized, maintained, or endorsed by Instagram or Meta. Instagram is a trademark of Meta Platforms, Inc. You are responsible for using the data in line with applicable law and Instagram's terms.

License

MIT

Metadata

Release files for herascrape 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Loss of provenance

These files do not have provenance metadata, despite files in a prior release including this data.

We recommend further investigation before installing these files. View details.

Source distribution (sdist)

Source distribution for herascrape 0.1.6
File Size Uploaded Provenance Actions
herascrape-0.1.6.tar.gz 14.3 kB Without provenance Details for herascrape-0.1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for herascrape 0.1.6
File Interpreter ABI Platform Actions
herascrape-0.1.6-py3-none-any.whl Python 3 none any Details for herascrape-0.1.6-py3-none-any.whl

Total release size: 34.2 kB

Release files / herascrape-0.1.6.tar.gz

Loss of provenance

This file belongs to a release without provenance metadata, despite a prior release including this data.

We recommend further investigation before installing this file. View details.

Download URL herascrape-0.1.6.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b886ccda7cb2914ce6ebfa89e868ca08cb8c490dab9d93af0e8ad36d1fa00b6b
BLAKE2b-256 checksum
How to use checksums
7ac890e91b6fceef06f5939f3d9a03cad3b36558beca5d12df8a7d2860876045
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.14 {"installer":{"name":"uv","version":"0.12.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / herascrape-0.1.6-py3-none-any.whl

Loss of provenance

This file belongs to a release without provenance metadata, despite a prior release including this data.

We recommend further investigation before installing this file. View details.

Download URL herascrape-0.1.6-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8ce472d3c2b1ee93c04d7e5de1b92fd1f79abf642d1ea25f47d843ebeb2d474
BLAKE2b-256 checksum
How to use checksums
0aeeb91c692cf7645f0a66671d168a7956cfa9cc650f5e49ae81751d4442b469
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.14 {"installer":{"name":"uv","version":"0.12.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for herascrape 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Loss of provenance

A previous release of these files had provenance metadata, but this release does not.

While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.

Release comparison

  • Removed 0.1.5 2 files With provenance
  • Added 0.1.6 2 files Without provenance

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page