pyhood
A modern Python client for the Robinhood API, built for scripts that need to stay authenticated.
pyhood is a modern, typed, maintained Python client for Robinhood. It supports stocks, options, retirement accounts, futures, banking, documents, research endpoints, and Robinhood's official Crypto Trading API. It is built for automation: authenticate once, persist a session safely, and renew it later without a password, device approval prompt, or human in the loop.
pyhood is an unofficial client and is not affiliated with Robinhood. Use responsibly. This project is not financial advice.
Install
pyhood installs into a folder of its own, and that folder is also where you work from. With uv (brew install uv on macOS):
uv venv --managed-python --python 3.14 ~/pyhood
uv pip install --python ~/pyhood/bin/python pyhood
That creates ~/pyhood, holding pyhood, its own copy of Python, and an AGENTS.md that tells an AI agent what to do there. The command is ~/pyhood/bin/pyhood. To type just pyhood from any folder, link it into a folder on your PATH:
ln -s ~/pyhood/bin/pyhood ~/.local/bin/pyhood
The rest of this page writes pyhood. If you skipped the link, type ~/pyhood/bin/pyhood.
--managed-python tells uv to use a Python it downloads and keeps for itself. Without it uv may borrow your system's or Homebrew's Python, and the install breaks when that one is upgraded or removed.
Upgrade later with uv pip install --python ~/pyhood/bin/python --upgrade pyhood.
Installing with pip instead
pyhood needs Python 3.10 or newer.
python3.14 -m venv ~/pyhood
~/pyhood/bin/python -m pip install --upgrade pip
~/pyhood/bin/python -m pip install pyhood
Substitute whichever interpreter you have; 3.10 through 3.14 are tested. On Windows the commands are in pyhood\Scripts rather than pyhood/bin.
Two things to know about this route:
- Name the version explicitly.
python3on macOS is still 3.9, and an environment built from it cannot install pyhood. The error readsno matching distribution found, which looks like the package is missing rather than a version problem. - The environment depends on the Python that created it. If that Python is later removed, as Homebrew does when it retires a version, the environment stops working and has to be rebuilt.
To add pyhood to a project that already has its own environment, pip install pyhood there as usual.
Set Up Stocks, Options and Futures
pyhood setup login # store a session
pyhood verify # confirm it works
setup login prompts for your username and password, then waits for you to approve the device in the Robinhood mobile app. The password is read without echoing and is never stored. Only the resulting tokens are saved, to ~/.pyhood/session.json, readable only by you.
pyhood verify is a read-only check: if it prints prices, you are authenticated and working.
Set Up Crypto
pyhood setup crypto # generate and register a key pair
pyhood verify crypto # confirm it works
Robinhood does not issue you a key pair for the Crypto Trading API. You generate one and register the public half. setup crypto runs that exchange, writes both parts to ~/.pyhood/crypto.env at mode 0600, and then makes one signed read-only call to confirm Robinhood accepts them. The private key goes straight from generation to disk and is never displayed.
pyhood verify crypto re-runs that check any time, and reports which source your credentials resolve from, which is useful when a stale export is shadowing the file.
Run pyhood setup at any time to see what is configured. See Setup for the full walkthrough.
From the Command Line
The questions asked most often need no code:
pyhood positions # what you hold, with profit and loss
pyhood orders # orders from the last 30 days, newest first
pyhood orders --since 2026-01-01 --symbol AAPL
pyhood buying-power # cash available to trade with
pyhood quote AAPL MSFT # current prices; add --fundamentals for more
pyhood options AAPL # option expirations; add --expires DATE for contracts
Orders since 2026-10-25 (times are EST; today is 2026-11-24)
PLACED SIDE SYMBOL TYPE ORDERED LIMIT FILLED AVG PRICE STATUS
2026-11-19 12:36 EST buy AAPL stock 10 $350.00 10 $349.80 filled
2026-11-19 11:31 EST buy AAPL stock 10 $340.00 0 - cancelled
Those are read-only. Each prints a table with times in your own time zone, and takes --json for exact values.
Placing orders
pyhood buy and pyhood sell work in two steps. Run once, a command only previews:
$ pyhood buy AAPL 10 --limit 350
PREVIEW. Nothing has been sent.
Buy 10 AAPL, limit $350.00, good for day
Estimated cost: $3,500.00
AAPL now: $352.01 (bid $351.99, ask $352.01)
Buying power: $5,000.00
Market open: yes
To place this order, show this preview to the user. If they say yes, run:
pyhood buy AAPL 10 --limit 350 --confirm 98dee3
Option orders work the same way, with every term of the contract named:
pyhood buy-option AAPL --expires 2026-12-18 --strike 350 --call --contracts 1 --limit 2.50
Run again with the code it printed, and the order is placed. The code belongs to that exact order on that day: change the symbol, quantity or price and it is refused, so what is placed is always what was previewed. An order needs --limit PRICE or --market; there is no default.
The code is a guardrail against mistakes, not a lock. Anything that can run the preview can read the code.
pyhood cancel ORDER_ID cancels an order in one step. A cancel names one order and can only remove it, and when you want out of an order a second step is time in which it can fill.
Use It With an AI Agent
pyhood is built to be driven by an AI agent. Open your agent in the install folder:
cd ~/pyhood
The install put an AGENTS.md there, which agents that follow that convention read when they start. It tells the agent to run pyhood guide, and the guide gives it the rest: the commands, how to run a script, and the rules for placing orders. There is nothing to set up by hand.
To use pyhood from some other folder, put one line in that folder's AGENTS.md (or CLAUDE.md):
pyhood is installed on this machine. Run `pyhood guide` before using it.
Without either, an agent has to find pyhood for itself. In testing, a model given no instructions took 15 to 19 commands to answer a question it answers in 2 or 3 with them, and along the way printed the saved session file to look at it.
What makes this dependable:
- Orders are previewed before they are placed.
pyhood buyshows the order, its cost and any problem with it, and places nothing until it is run again with the code the preview printed. The guide tells the agent to show you the preview and wait for a yes. - The commands above answer most questions with no script. An agent asked what you bought runs
pyhood ordersand reads a table. Left to write a script, models trip on the same things: formatting the price of an order that never filled, which isNone, and reading UTC timestamps as local time. pyhood run script.pyruns a script with the Python pyhood is installed in. An agent does not have to find the right Python.- Errors say what to do. A wrong field name lists the real ones. An unsupported Python, or running from a source folder, says so instead of failing somewhere unrelated.
An agent with your session can place real orders. The guide tells it to preview, show you, and wait for a yes, and the confirmation code makes it preview first. But those are an instruction and a guardrail, not a lock. Give session access only to an agent you would trust with the account.
Quick Start
Once pyhood setup login has stored a session, no credentials appear in your code at all:
import pyhood
from pyhood.client import PyhoodClient
# Reuses the stored session, refreshing it if the access token has expired.
session = pyhood.login()
client = PyhoodClient(session)
quote = client.get_quote("AAPL")
print(f"AAPL: ${quote.price:.2f} ({quote.change_pct:+.1f}%)")
positions = client.get_positions()
buying_power = client.get_buying_power()
Save that as script.py and run it with pyhood run script.py.
login() with no arguments tries the cached session, then the refresh token. To force a refresh explicitly:
session = pyhood.refresh()
Why pyhood exists
pyhood began with a specific problem: unattended Robinhood scripts should not die just because a session expired.
The original Python Robinhood client, robin_stocks, made Robinhood automation accessible to a large community and remains the best-known library in this space. But Robinhood's authentication flow has changed over time, and many users now run into the same failure mode: a script works for a few days, the session expires, and the next login waits for a device approval no one is there to tap. pyhood fixes that workflow. After the first approved login, pyhood stores refresh-token session data as JSON and can renew the session with:
session = pyhood.refresh()
No username. No password. No device approval prompt.
That makes pyhood a better fit for cron jobs, scheduled portfolio scripts, dashboards, and automated trading systems that need to keep running without a human nearby.
Why use pyhood?
- Silent session refresh - renew Robinhood sessions without credentials or device approval after the first login.
- Typed responses - dataclass responses and type hints instead of guessing through raw dictionaries.
- Retirement accounts - discover and trade in Traditional and Roth IRA accounts.
- Official crypto API - use Robinhood's official Crypto Trading API with API keys.
- Futures support - futures contracts, quotes, orders, positions, and P&L helpers.
- Options-first coverage - equity and index options, chains, Greeks, volume, open interest, and order helpers.
- Safer session storage - JSON session persistence instead of
pickle. - Rate limiting and retries - request throttling and retry behavior built in.
- Clear auth errors - explicit exceptions for timeouts, MFA, expired tokens, and device approval failures.
- Maintained test suite - 360 tests, CI across Python 3.10 through 3.14.
How pyhood compares
Against robin_stocks and the actively maintained fork robin_stocks_v2:
| Capability | pyhood | robin_stocks | robin_stocks_v2 |
|---|---|---|---|
| Silent session refresh without credentials | Yes | No | No |
| JSON session storage | Yes | No, uses pickle | Yes |
| IRA / retirement accounts | Yes | No | No |
| Official Crypto Trading API | Yes | No | No |
| Futures contracts and quotes | Yes | No | Yes |
| Futures positions | Yes | No | Stubbed |
| IPO access | Yes | No | Yes |
| Typed dataclass responses | Yes | No | Partial |
| Index options: SPX, NDX, VIX, RUT, XSP | Yes | Partial | Yes |
| Order history date filtering | Yes | Yes | Yes |
| Minimum Python version | 3.10 | 3.9 | 3.10 |
Migrating from robin_stocks? See the migration guide for a function-by-function map. Coming from pyrh, which has not been updated since August 2024? There is a pyrh guide too.
Setup
pyhood uses two unrelated kinds of credential, and pyhood setup configures either one.
| Command | Credential | Stored at |
|---|---|---|
pyhood setup login |
Session tokens for the main API — stocks, options, futures | ~/.pyhood/session.json |
pyhood setup crypto |
Ed25519 key pair for the Crypto Trading API | ~/.pyhood/crypto.env |
pyhood setup |
— | reports what is configured |
Both files are created 0600 inside a 0700 directory, with the mode applied at creation so the contents are never briefly readable by others.
setup login tries the stored session first — a valid or refreshable one needs no password at all. Only when that fails does it prompt for your username and password, handling MFA and device approval. The password is read without echoing and is never stored; only the resulting tokens are written.
setup crypto generates an Ed25519 key pair on your machine, prints only the public half for you to register with Robinhood, then reads the API key Robinhood issues and writes both to disk. The private key goes straight from generation to file — it is never displayed. Afterwards it makes one signed read-only call to confirm Robinhood actually accepts the pair, which is the step that catches a mistyped or placeholder key immediately rather than at your first order.
setup with no target reports what is configured — where credentials came from, file permissions, and whether the private key is a real Ed25519 key. It shows lengths and validity, never values, and makes no network calls.
$ pyhood setup
Session (main API — stocks, options, futures)
/Users/you/.pyhood/session.json (refreshable, saved 1.2h ago)
Crypto API (official Crypto Trading API)
source: file
/Users/you/.pyhood/crypto.env
api key: 43 chars
private key: valid Ed25519, 32 bytes
Secrets are only ever read interactively. There are deliberately no --password or --api-key options: arguments are visible to every process on the machine via ps and are recorded by your shell.
Authentication
Robinhood requires device approval on first login. After that, pyhood keeps the session alive automatically.
First Login
Run pyhood setup login and approve the device prompt in the Robinhood mobile app when it appears. The session is saved to ~/.pyhood/session.json.
To log in from code instead:
import pyhood
session = pyhood.login(
username="you@email.com",
password="your_password",
timeout=90,
)
Prefer the setup command where you can — a password written into a script tends to end up committed.
Staying Authenticated
# Reuses cached session data.
session = pyhood.login(username="you@email.com", password="your_password")
# Or refresh explicitly with no credentials.
session = pyhood.refresh()
Access sessions have been observed to last several days. When the access token expires, pyhood refreshes it using the stored refresh token.
Device approval is only needed again if the refresh token itself expires or Robinhood invalidates the session.
Error Handling
from pyhood.exceptions import (
AuthError,
DeviceApprovalRequiredError,
LoginTimeoutError,
MFARequiredError,
TokenExpiredError,
)
try:
session = pyhood.login(username="...", password="...", timeout=90)
except LoginTimeoutError:
print("Open Robinhood and approve the device, then try again.")
except MFARequiredError:
code = input("Enter the code from SMS/email: ")
session = pyhood.login(username="...", password="...", mfa_code=code)
except AuthError as e:
print(f"Login failed: {e}")
Rate Limits
Robinhood aggressively rate-limits authentication attempts.
If login fails:
- Do not retry immediately.
- Wait at least 5 minutes.
- Multiple failed attempts can temporarily lock API access.
- Each new login attempt may generate a new device approval request.
See the rate limits documentation for details.
Common Examples
Options Chain
chain = client.get_options_chain("SPX", expiration="2026-04-17")
for option in chain.calls:
print(
option.strike,
option.iv,
option.delta,
option.open_interest,
)
IRA Trading
accounts = client.get_all_accounts()
order = client.buy_option(
symbol="NKE",
strike=55.0,
expiration="2026-04-02",
option_type="call",
quantity=3,
price=1.60,
account_number="YOUR_IRA_ACCOUNT",
)
See the account documentation for IRA account discovery and limitations.
Crypto Trading
from pyhood.crypto import CryptoClient
# Credentials are read from ~/.pyhood/crypto.env or the environment
crypto = CryptoClient()
quotes = crypto.get_best_bid_ask("BTC-USD", "ETH-USD")
account = crypto.get_account()
order = crypto.place_order(
account_number=account.account_number,
side="buy",
order_type="market",
symbol="BTC-USD",
order_config={"asset_quantity": "0.001"},
)
Getting API keys. Robinhood does not issue you a key pair — you generate one and register only the public half. The setup command walks through it:
pyhood setup crypto
It generates the key pair, shows you the public key to paste at robinhood.com/account/crypto → API Trading → Add key, reads the API key Robinhood issues back, writes both to ~/.pyhood/crypto.env at mode 0600, and then makes one signed read-only call to confirm the pair works. The private key is never displayed.
If you would rather do it by hand, the file is a plain env file:
# ~/.pyhood/crypto.env (chmod 600)
RH_CRYPTO_API_KEY=the-key-robinhood-issued
RH_CRYPTO_PRIVATE_KEY=the-private-key-you-generated
The private key is the credential — anyone holding it can trade your crypto, and unlike a session token it cannot be refreshed, only revoked. Environment variables take precedence over this file, so a stale export will silently shadow it; pyhood setup reports which source is in use.
Only pairs with api_tradable set can be ordered through the API — a pair can be tradable in the app but not here. See the crypto documentation for details.
Futures
contract = client.get_futures_contract("ESH26")
quote = client.get_futures_quote("ESH26")
pnl = client.calculate_futures_pnl()
print(contract.name, quote.last_price, pnl)
See the futures documentation for details.
Portfolio and Documents
performance = client.get_portfolio_performance()
docs = client.get_documents(doc_type="account_statement")
get_portfolio_historicals() raises APIError — Robinhood retired that endpoint. get_portfolio_performance() returns the chart view model that replaced it, unmapped, since its y values are returns rather than equity.
Feature Status
| Area | Status |
|---|---|
| Stocks and options market data | Functional |
| Equity and index options | Functional |
| Stock and option order management | Functional |
| Authentication with automatic refresh | Functional |
| Official crypto trading API | Functional |
| Futures contracts, quotes, orders, and P&L | Functional |
| IRA / retirement accounts | Functional |
| Banking, ACH transfers, and dividends | Functional |
| Watchlists | Functional |
| Markets and trading hours | Functional |
| Research, news, ratings, and movers | Functional |
| Option historicals and portfolio performance | Functional |
Guided credential setup (pyhood setup) |
Functional |
| Documents and statements | Functional |
| Day trades, margin calls, and deposit schedules | Functional |
Documentation
- Full documentation
- Migration guide: robin_stocks
- Migration guide: pyrh
- Account documentation
- Crypto documentation
- Futures documentation
- Rate limits
Contributing
Contributions are welcome, especially:
- endpoint coverage
- typed response models
- migration examples from
robin_stocks - documentation improvements
- tests for live-verified behavior
Please avoid opening pull requests that place real trades in tests.
Acknowledgments
pyhood stands on the shoulders of the community that mapped Robinhood's unofficial API:
- robin_stocks by Josh Fernandes, the most widely used Python Robinhood library.
- pyrh, an early client that helped establish OAuth token refresh patterns.
- Robinhood by Sanko, early unofficial endpoint documentation.
Those projects made Robinhood accessible to Python developers. pyhood continues that work with a focus on reliability, typed interfaces, and unattended automation.
License
MIT
Metadata
Release files for pyhood 0.18.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyhood-0.18.0.tar.gz | 161.2 kB | With provenance | Details for pyhood-0.18.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyhood-0.18.0-py3-none-any.whl | Python 3 | none | any | Details for pyhood-0.18.0-py3-none-any.whl |
Total release size: 253.3 kB
Release files / pyhood-0.18.0.tar.gz
| Download URL | pyhood-0.18.0.tar.gz |
|---|---|
| Size | 161.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf89c73ee88da3d12e1266b07b4845031723f067466f5dd44d5ce1de2a2cb410
|
|
BLAKE2b-256 checksum How to use checksums |
f8b914858296cfad3445e268e0a281d0bb96d439edefdacfa8e725f7caa8324f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logRelease files / pyhood-0.18.0-py3-none-any.whl
| Download URL | pyhood-0.18.0-py3-none-any.whl |
|---|---|
| Size | 92.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4cc3cd0cceda4c3f326bcb2cb941279263a9331e3b0faf75018f4e7386642ce8
|
|
BLAKE2b-256 checksum How to use checksums |
933f4e426b29b83dd426877eb5205e4993811757066c69a2206eb2a17baa4507
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logSecurity for pyhood 0.18.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pyhood-0.18.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.
Transparency logA 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.