Singer tap for the Meta Graph API (Instagram Insights), built with the Meltano Singer SDK.
Project description
tap-instagram-user
tap-instagram-user is a Singer tap for the Meta Graph API (Instagram Insights), built with the Meltano Singer SDK.
It extracts Instagram insights metrics (views, reach, impressions, ...) day by day, following an ELT strategy: no business transformation is applied by the tap, the raw API response is stored in a raw_data column (JSON), alongside metadata (ig_user_id, metric_name, breakdown_type, metric_date, extraction_date).
Installation
uv sync
Configuration
Main settings
| Setting | Required | Description |
|---|---|---|
access_token |
yes | Long-Lived Meta Token for the professional Instagram account |
ig_user_id |
yes | Professional Instagram account ID |
metrics |
yes | List of metrics (and their breakdowns) to extract — see below |
start_date |
on first run | Start date on first extraction (ignored once a bookmark exists). No default — required on a stream's first run, settable globally or per metric |
days_to_subtract |
no (default 0) |
Overlap window: number of already-covered days to re-extract on each run (useful because Meta insights can still be corrected after the fact) |
period |
no (default "day") |
Granularity requested from the Meta Insights API |
timeframe |
no | Optional timeframe parameter passed to the API |
metric_type |
no (default "total_value") |
metric_type parameter passed to the API |
generate_dates_range |
no (default "active") |
"active" = one API call per day; "inactive" = a single call covering the whole range |
metrics
Each entry defines a metric and generates one stream per metric/breakdown combination (e.g. views + follow_type -> stream ig_user_insights_views_by_follow_type; reach with no breakdown -> ig_user_insights_reach). An entry may override any of the settings above (except access_token/ig_user_id, always global) for itself only:
{
"metrics": [
{
"metric": "views",
"breakdowns": ["follow_type,media_product_type", "follow_type", "media_product_type"]
},
{
"metric": "reach",
"breakdowns": [""],
"days_to_subtract": 2,
"start_date": "2026-01-01T00:00:00Z"
},
{
"metric": "impressions",
"breakdowns": ["media_product_type"],
"generate_dates_range": "inactive",
"period": "week",
"timeframe": "last_30_days"
}
]
}
See config.template.json for a full example.
Media extraction (optional)
In addition to account-level (user) insights, the tap can extract media (posts) and their per-post insights. This is opt-in: media streams are only discovered when media_fields is set, so user-only setups are unaffected.
Two levels, mirroring the Meta API:
ig_media— the account's media list (GET /{ig_user_id}/media), cursor-paginated. One row per post per day (snapshot), raw post JSON stored inraw_data.ig_media_insights_<metric>— per-post insights (GET /{id_post}/insights), one stream per metric/breakdown (child ofig_media). One row per post × metric.
Stream names follow ig_<node>_<edge>[_<metric>[_by_<breakdown>]] (e.g. ig_user_insights_reach, ig_media_insights_views), with the bare node (ig_media) for the object list itself. The explicit edge segment keeps names collision-free as more Meta edges are added (e.g. a future ig_media_comments edge never clashes with the comments insight metric ig_media_insights_comments).
| Setting | Required | Description |
|---|---|---|
media_fields |
yes (to enable media) | Fields requested on the /media edge. No default (Meta-controlled vocabulary). Must include media_product_type — the insights children use it to filter valid metrics. |
media_limit |
no (default 100) |
Page size (limit) for /media |
media_max_pages |
no (default 100) |
Safety cap on pagination |
media_metrics |
yes (for insights) | List of per-post metrics (and optional breakdowns), same shape as metrics |
media_metric_compatibility |
yes (with media_metrics) |
Maps each media_product_type (FEED/REELS/STORY) to its valid metrics. No default. |
{
"media_fields": ["id", "timestamp", "media_type", "media_product_type", "like_count", "comments_count"],
"media_metrics": [
{ "metric": "reach" },
{ "metric": "views" },
{ "metric": "profile_activity", "breakdowns": ["action_type"] }
],
"media_metric_compatibility": {
"FEED": ["reach", "views", "likes", "comments", "profile_activity"],
"REELS": ["reach", "views", "likes", "comments"],
"STORY": ["reach", "replies", "navigation"]
}
}
Why media_metric_compatibility is config (not hardcoded): Meta only supports certain metrics per media type, and that vocabulary changes over time. Keeping it in config means a Meta change is fixed by editing config, not by republishing the package. At runtime, a metric is requested for a post only if it is in both media_metrics and media_metric_compatibility[<post type>]. If Meta still rejects a metric the table claims is valid, the run fails loudly (stale-table signal) rather than silently dropping data.
User and media streams are independent — run only user insights by selecting only the ig_user_* streams (media children additionally depend on the ig_media parent at runtime). See select: in meltano.yml.
Configuration via environment variables
Copy .env.example to .env and fill in the real values (never committed). Meltano convention: <PLUGIN_NAME>_<SETTING_NAME> in uppercase, e.g. TAP_INSTAGRAM_USER_ACCESS_TOKEN.
The full list of settings is available via:
tap-instagram-user --about
Usage
Direct CLI (without Meltano)
tap-instagram-user --config config.json --discover > catalog.json
tap-instagram-user --config config.json --catalog catalog.json --state state.json
Via Meltano (recommended)
# Install the Meltano CLI (if not already done)
pipx install meltano
# Install the plugins declared in meltano.yml
meltano install
# Check the config
meltano config tap-instagram-user list
meltano config test tap-instagram-user
# Run the pipeline (extract -> load into Postgres)
meltano run tap-instagram-user target-postgres
Meltano automatically manages state (bookmarks) between runs via its own system database — no need to manually handle a state.json file.
Development
Tests
uv run pytest
Notable implementation details
- Bookmark: based on each day partition's
until, capped so it never regresses (notably during the monthly consolidation). A single bookmark per stream (state_partitioning_keys = []), not one per partition. - Primary key: includes
metric_date(the day the data is for) in addition toig_user_id/metric_name/breakdown_type, to prevent an upsert on the target side from overwriting another day's data. - Monthly consolidation: on the 1st of the month, the tap automatically re-extracts the entire month before last (Meta insights can still be corrected after publication).
- Media (
ig_media/ig_media_insights_<metric>): a daily snapshot, not a time series (nosince/until; the media insights edge always reportslifetime). Theig_mediaparent is cursor-paginated and guarded against running twice the same day; the per-metric children are SDK child streams (parent_stream_type) that receive each post'smedia_product_typeand only call metrics declared valid for it.
See the code in tap_instagram_user/streams.py and tap_instagram_user/client.py for details.
SDK Dev Guide
See the Meltano Singer SDK dev guide for more information.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file plinxore_tap_instagram_user-0.3.0.tar.gz.
File metadata
- Download URL: plinxore_tap_instagram_user-0.3.0.tar.gz
- Upload date:
- Size: 25.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3321dc018e4695a79c83801ad4c6b2c710bd649570648b5dba225fa29b9127e6
|
|
| MD5 |
52431940de76274cf9ec5c8b69690bb3
|
|
| BLAKE2b-256 |
04c44fdda4b8b2bf6d8f9573b7216bb2573f9db7cd3eb524b9682d18223164a5
|
File details
Details for the file plinxore_tap_instagram_user-0.3.0-py3-none-any.whl.
File metadata
- Download URL: plinxore_tap_instagram_user-0.3.0-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b01defd891fdde1c464bbbd856397bd26e6e3763250b6a566c9296b1d561aee6
|
|
| MD5 |
0c7a22c8565d21687266d2dd21a9826f
|
|
| BLAKE2b-256 |
bf5e988c47f6a0b1a715e52bb47f53f3e5d323d9d8a57469baba97beb26f9b20
|