Skip to main content

Instagram Private API Extensions

An extension module to instagram_private_api to help with common tasks such as posting a photo or video.

Release Docs Build Coverage

Features

  1. media: Edits a photo/video so that it complies with Instagram's requirements by:

    • Resizing
    • Cropping to fit the minimum/maximum aspect ratio
    • Generating the video thumbnail image
    • Clipping the video duration if it is too long
    • Changing the format/encoding
  2. pagination: Page through an api call such as api.user_feed().

  3. live: Download an ongoing IG live stream. Requires ffmpeg installed.

  4. replay: Download an IG live replay stream. Requires ffmpeg installed.

Documentation

Documentation is available at https://instagram-private-api-extensions.readthedocs.io/en/latest/

Install

Install with pip using

pip install git+https://git@github.com/ping/instagram_private_api_extensions.git@0.3.8

To update:

pip install git+https://git@github.com/ping/instagram_private_api_extensions.git@0.3.8 --upgrade

To update with latest repo code:

pip install git+https://git@github.com/ping/instagram_private_api_extensions.git --upgrade --force-reinstall

Usage

Media

from instagram_private_api import Client, MediaRatios
from instagram_private_api_extensions import media

api = Client('username', 'password')

# post a photo
photo_data, photo_size = media.prepare_image(
    'pathto/my_photo.jpg', aspect_ratios=MediaRatios.standard)
api.post_photo(photo_data, photo_size, caption='Hello World!')

# post a video
vid_data, vid_size, vid_duration, vid_thumbnail = media.prepare_video(
    'pathto/my_video.mp4', aspect_ratios=MediaRatios.standard)
api.post_video(vid_data, vid_size, vid_duration, vid_thumbnail)

# post a photo story
photo_data, photo_size = media.prepare_image(
    'pathto/my_photo.jpg', aspect_ratios=MediaRatios.reel)
api.post_photo_story(photo_data, photo_size)

# post a video story
vid_data, vid_size, vid_duration, vid_thumbnail = media.prepare_video(
    'pathto/my_video.mp4', aspect_ratios=MediaRatios.reel)
api.post_video_story(vid_data, vid_size, vid_duration, vid_thumbnail)

# post a video without reading the whole file into memory
vid_saved_path, vid_size, vid_duration, vid_thumbnail = media.prepare_video(
    'pathto/my_video.mp4', aspect_ratios=MediaRatios.standard,
    save_path='pathto/my_saved_video.mp4', save_only=True)
# To use save_only, the file must be saved locally
# by specifying the save_path
with open(vid_saved_path, 'rb') as video_fp:
    api.post_video(video_fp, vid_size, vid_duration, vid_thumbnail)

Pagination

from instagram_private_api_extensions import pagination

# page through a feed
items = []
for results in pagination.page(api.user_feed, args={'user_id': '123456'}):
    if results.get('items'):
        items.extend(results['items'])
print(len(items))

Live

from instagram_private_api_extensions import live

broadcast = api.broadcast_info('1234567890')

dl = live.Downloader(
    mpd=broadcast['dash_playback_url'],
    output_dir='output_{}/'.format(broadcast['id']),
    user_agent=api.user_agent)
try:
    dl.run()
except KeyboardInterrupt:
    if not dl.is_aborted:
        dl.stop()
finally:
    # combine the downloaded files
    # Requires ffmpeg installed. If you prefer to use avconv
    # for example, omit this step and do it manually
    dl.stitch('my_video.mp4')

Replay

from instagram_private_api_extensions import replay

user_story_feed = api.user_story_feed('12345')

broadcasts = user_story_feed.get('post_live_item', {}).get('broadcasts', [])
for broadcast in broadcasts:
    dl = replay.Downloader(
        mpd=broadcast['dash_manifest'],
        output_dir='output_{}/'.format(broadcast['id']),
        user_agent=api.user_agent)
    # download and save to file
    dl.download('output_{}.mp4'.format(broadcast['id']))

Support

Make sure to review the contributing documentation before submitting an issue report or pull request.

Metadata

Release files for instagram-private-api-extensions 0.3.8

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

Source distribution (sdist)

Source distribution for instagram-private-api-extensions 0.3.8
File Size Uploaded
instagram_private_api_extensions-0.3.8.tar.gz 16.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for instagram-private-api-extensions 0.3.8
File Interpreter ABI Platform
instagram_private_api_extensions-0.3.8-py3-none-any.whl Python 3 none any Details

Total release size: 35.8 kB

Release files / instagram_private_api_extensions-0.3.8.tar.gz

Download URL instagram_private_api_extensions-0.3.8.tar.gz
Size 16.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8c50104966868cce36303d31e21edc4fbab662102cc483c135d304b315de9372
BLAKE2b-256 checksum
How to use checksums
825a1e5e7185cfbb4545f43a81c420be3cb47c3b46a63da556c77ecca3cffa96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

Release files / instagram_private_api_extensions-0.3.8-py3-none-any.whl

Download URL instagram_private_api_extensions-0.3.8-py3-none-any.whl
Size 19.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
46a68b001605cafdcce193ffed3ce09e68c347ffc0d6db1883fdc88bca8f4aeb
BLAKE2b-256 checksum
How to use checksums
fb3af9e594ab71d17f2deb59ab94c901914bc69a3b229b496c4cd70c5e89d6de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

Release history Release notifications | RSS feed

This release

0.3.8 This release

2 release files

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