Rotate to portrait

Vizual Stocks works best vertically on mobile.

VizualStocks API

PYTHON TUTORIAL · INVESTOR RESEARCH

Download historical short interest data with Python

Follow how a stock’s reported short interest changes over time. Download Palantir’s history, export it to CSV, and plot shares shorted alongside short interest as a percentage of float. Then repeat with a ticker from your own watchlist.

01 · SETUP

Install Python libraries and set your API key

You’ll need Python 3.10 or newer. Save historical_short_interest.py in your working folder and run:

Terminal · install dependencies
python -m pip install requests pandas matplotlib

Log in to get your API key. In the dashboard, click Create API key → Create key → Copy, then return here and replace YOUR_API_KEY below.

Windows PowerShell
$env:VIZUALSTOCKS_API_KEY = "YOUR_API_KEY"
macOS / Linux shell
export VIZUALSTOCKS_API_KEY="YOUR_API_KEY"

Choose the command for your terminal. The key stays in your environment and is sent through the X-API-Key header, not a URL or exported file.

02 · DOWNLOAD

Get a stock’s historical short interest

Start with PLTR. This command requests the available history in ascending settlement-date order and creates a new output folder:

Terminal · export PLTR history
python historical_short_interest.py --ticker PLTR --output-dir pltr-short-interest

It calls GET /v1/companies/PLTR/short-interest?order=asc, then writes a CSV, a PNG chart and readme.json with retrieval notes. No history limit is supplied.

Choose a settlement-date range

Terminal · export a date range
python historical_short_interest.py --ticker PLTR --from 2026-01-01 --to 2026-08-31 --output-dir pltr-short-interest-2026

--from and --to are inclusive. They filter settlement dates, not the dates on which investors first learned the numbers. Use a new output directory for each export.

Find another company

Terminal · discover coverage
python historical_short_interest.py --list-companies

This retrieves your accessible company list and selects entries with hasShortInterest. Replace PLTR and the output folder in the export command with your chosen ticker. History length varies by company.

03 · OUTPUT

Read the short-interest CSV and chart

The CSV keeps one row per reported settlement date. Share counts remain whole shares; the top chart displays them in millions for readability. The bottom chart uses the API’s reported percentage of float.

What each exported column means
ColumnMeaning
tickerThe selected stock symbol.
settlementDateDate of the reported position snapshot, not publication time.
sharesShortedReported shares held short.
sharesFloatFloat supplied for that observation; blank when unavailable.
shortInterestPercentageReported percent of float: 2.97 means 2.97%, not 297%.
sharesShortedChangeChange in shares shorted versus the previous returned observation.
shortInterestChangePpChange in the reported percentage, measured in percentage points.

For example, a move from 3% to 4% is +1 percentage point, not +1%. The first row has no previous observation, so its change columns are blank. A missing value also leaves the corresponding change blank.

The chart connects reported observations for readability; it does not reconstruct positions on the days between them. A change in percentage of float can reflect a change in shares shorted, a change in float, or both—compare the two panels.

04 · PANDAS

Use the same data in a Python notebook

Keep the downloaded script beside your notebook. These helpers perform the same request and validation as the command-line export:

Python · fetch and inspect history
from historical_short_interest import make_session, api_get, short_interest_frame

with make_session() as session:
    history = api_get(
        session, "/companies/PLTR/short-interest", order="asc"
    )

frame = short_interest_frame(history, "PLTR")
print(frame.tail(5).to_string(index=False))

The DataFrame sorts settlement dates, retains nullable numeric columns and rejects duplicate dates. To save your own table:

Python · export a DataFrame
# Blank values stay blank; an existing file is never overwritten.
frame.to_csv("pltr-notebook.csv", index=False, na_rep="", mode="x")

Do not forward-fill missing float values or assume the first available row is the company’s first-ever short-interest report. This is the available API history for your request.

05 · INTERPRETATION

Short interest is not daily short-sale volume

Short interest measures positions still open at a reporting date. Short-sale volume measures trading activity during a day; a sale may be closed out without remaining in the reported position. FINRA explains why the two datasets are not interchangeable.

This tutorial uses reported short-interest positions. It does not provide daily short-sale volume, borrow fees or days to cover. The endpoint also does not return original publication timestamps, so settlement dates should not be treated as “known on this date” inputs for a trading backtest.

For an investor’s watchlist, this is a repeatable way to review changes and keep a dated research export. A high short-interest percentage alone does not establish why positions were opened or predict a price move.

06 · TROUBLESHOOTING

If your download does not run

401 or 403
Check that the key is set in this terminal, is active and has access to short-interest data. Check its status in the API dashboard.
429 or a temporary server error
The script retries eligible GET requests up to three times with backoff and respects Retry-After. If retries fail, wait before rerunning and check your quota.
No history returned
Try discovery, check your ticker and widen the date range. An empty response does not mean the stock has zero short interest.
Output directory already exists
Choose a new --output-dir. The script protects previous exports. If an earlier run stopped partway through, its partial files remain in that directory for inspection.
Python cannot import a library or helper
Run the install command with the same Python interpreter as your script or notebook, and work in the folder containing historical_short_interest.py.

Repeat the workflow for your watchlist

Choose another covered ticker, save a separate export and compare reported changes without turning settlement snapshots into daily estimates.

References: FINRA: short interest vs. short-sale volume · pandas CSV export · Matplotlib subplots