Skip to main content

BasketCase

Download images and videos from Instagram.

Notable features:

  • Stories can be downloaded without being seen.
  • Downloads media from a list of URLs.
  • Downloads media of the highest quality available.
  • Downloads a high-quality profile picture.

"Green Day - Basket Case" on YouTube 🤕

Installation methods

pipx

pipx greatly simplifies user installations and avoids conflicts with the system by isolating every program in its own virtual environment.

pipx install basketcase

venv

Or you could simply install it in a virtual environment created with the venv module.

python -m venv ~/.venv
. ~/.venv/bin/activate
pip install basketcase

Command-line usage

basketcase get "https://instagram.com/p/POST_ID"

Downloaded resources will be stored in the current working directory by default. Override with the get --output option.

To download from multiple URLs, create a text file (e.g. urls.txt) and populate it with resource URLs:

https://instagram.com/p/POST_ID
https://instagram.com/reel/REEL_ID
https://instagram.com/USERNAME
basketcase get ./urls.txt

See --help for more info.

Supported URLs

Supported URL Description
https://instagram.com/USERNAME User profile. Downloads stories from the past 24 hours, and the profile picture.
https://instagram.com/p/POST_ID Standard feed post
https://instagram.com/reel/REEL_ID Reels movie
https://instagram.com/stories/highlights/HIGHLIGHT_ID/ A collection of stories, or "highlights"
https://instagram.com/s/CODE An alternative URL commonly used for highlighted stories
https://instagram.com/tv/CODE Similar to reels

Session management

To retrieve your Instagram cookies, follow these steps:

  1. Navigate to instagram.com on your browser.
  2. Open up Developer Tools, switch to the Network tab, then reload the page.
  3. On the list, find the initial request that returns HTML, and inspect its request headers.
  4. Copy the value of the Cookie header and put it in a text file (e.g. cookies.txt).

Example cookies.txt:

datr=REDACTED; ig_did=REDACTED; csrftoken=REDACTED; mid=REDACTED; ig_nrcb=1; ds_user_id=REDACTED; sessionid=REDACTED; ps_l=1; ps_n=1; rur="REDACTED"; wd=773x818
basketcase session add-cookies ./cookies.txt --set-name "jane.doe"
# New session created (id=1) with 10 cookie(s)

This is the recommended method, since we should try to look like a real browser as much as we can to avoid "automated behavior" warnings.

Alternatively, add a single sessionid cookie.

basketcase session add-cookie "COOKIE_VALUE" --set-name "john.doe"
# New session created (id=1) with one 'sessionid' cookie

Specify its identifier when downloading.

basketcase get -s 1 URL_OR_FILE

List all available sessions with basketcase session list.

To disable sessions, use get --no-session.

If only one exists, it is treated as the default.

When the instance is closed (BasketCase.close()) or the script exits, cookies from the HTTP client are saved in the database. This keeps your cookies up-to-date.

User data

Cookies and other application data are kept in your home directory (i.e. ~/.basketcase).

Known limitations

This program relies on the APIs used by the web browser Instagram client, which can change without a notice.

Multiple authors, owner is private

Fails to locate a suitable extractor for a standard feed post with multiple authors, in which the owner - or main author - has a private profile you cannot see.

Development setup

This project uses pipenv for dependency and virtual environment management, so make sure it's installed. pipx is a convenient tool to manage your virtual-environment user installations, and it can be used to install pipenv.

1. Install build dependencies

These must be installed using the system package manager. The package name examples listed below are from Debian.

  • Python development headers and libraries (e.g. python3-dev).
  • lxml requires libxml2 and libxslt, as documented here (e.g. libxml2-dev libxslt-dev).
  • cffi requires libffi (e.g. libffi-dev).

2. Create the environment

cd to the project root, then run pipenv install --dev.

Test

To discover and run all tests in this project, activate the project venv, cd to the project root and run python -m unittest. Test coverage is still low and needs some effort.

Package build and upload

First, increment the version in pyproject.toml.

Then build the package.

python -m build

If that succeeds, commit and push the version change, then tag the release.

git tag -a VERSION_NUMBER -m 'Briefly describe the changes'
git push REMOTE VERSION_NUMBER

Finally, publish it.

python -m twine upload dist/*

Metadata

Release files for basketcase 8.0.3

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

Source distribution (sdist)

Source distribution for basketcase 8.0.3
File Size Uploaded
basketcase-8.0.3.tar.gz 31.3 kB Details

Built distribution (wheel)

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

Total release size: 62.5 kB

Release files / basketcase-8.0.3.tar.gz

Download URL basketcase-8.0.3.tar.gz
Size 31.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0f95db621fe3cc0c6691e06e5cedbf26adb1ebe62f7875234229ae50589754e2
BLAKE2b-256 checksum
How to use checksums
a3f7b21f7c8e394fafe522cb8f9d24f179b27a46bcfba62c7cc113deed8b9d4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / basketcase-8.0.3-py3-none-any.whl

Download URL basketcase-8.0.3-py3-none-any.whl
Size 31.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dcf7101df4bf996233b8855e7f6b5e1c0ed5138daca6e943326b2cea5abe0b0d
BLAKE2b-256 checksum
How to use checksums
e207dbf5cb89946224efdba585939e128e28dff3fa57d8cd19c1db425cfe2419
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release history Release notifications | RSS feed

This release

8.0.3 This release

2 release files

8.0.2

2 release files

8.0.1

2 release files

8.0.0

2 release files

7.2.0

2 release files

7.1.0

2 release files

7.0.2

2 release files

7.0.1

2 release files

7.0.0

2 release files

6.0.0

2 release files

5.0.0

2 release files

4.0.0

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.0.0

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.6

2 release files

0.0.2

2 release files

0.0.1

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