Skip to main content

pyhood

pyhood logo

A modern Python client for the Robinhood API, built for scripts that need to stay authenticated.

CI PyPI Docs Python 3.10+ License: MIT Security Code style: ruff

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

pip install pyhood

Quick Start

import pyhood
from pyhood.client import PyhoodClient

# First login may require device approval in the Robinhood mobile app.
session = pyhood.login(
    username="you@email.com",
    password="your_password",
    timeout=90,
)

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()

After the first approved login, pyhood can refresh the session without credentials:

import pyhood

session = pyhood.refresh()
client = PyhoodClient(session)

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 - CI across Python 3.10 through 3.13.

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.

Authentication

Robinhood requires device approval on first login. After that, pyhood keeps the session alive automatically.

First Login

  1. Open the Robinhood mobile app.
  2. Call pyhood.login().
  3. Approve the device prompt in the app.
  4. pyhood saves the session to ~/.pyhood/session.json.
import pyhood

session = pyhood.login(
    username="you@email.com",
    password="your_password",
    timeout=90,
)

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.implied_volatility,
        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:

python -c "from pyhood.crypto.auth import generate_keypair; priv, pub = generate_keypair(); print('PRIVATE:', priv); print('PUBLIC :', pub)"

Paste the public key at robinhood.com/account/crypto → API Trading → Add key. Robinhood then issues an API key. Save both:

# ~/.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. Environment variables take precedence over this file, so a stale export will shadow it; credentials_source() reports which 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

history = client.get_portfolio_historicals(
    account_number="123456",
    interval="day",
    span="year",
)

docs = client.get_documents(doc_type="account_statement")

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, movers, and popularity Functional
Portfolio and option historicals Functional
Documents and statements Functional
Day trades, margin calls, and deposit schedules Functional

Documentation

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:

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.11.0

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

Source distribution (sdist)

Source distribution for pyhood 0.11.0
File Size Uploaded Provenance Actions
pyhood-0.11.0.tar.gz 94.4 kB With provenance Details for pyhood-0.11.0.tar.gz

Built distribution (wheel)

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

Total release size: 153.2 kB

Release files / pyhood-0.11.0.tar.gz

Download URL pyhood-0.11.0.tar.gz
Size 94.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3ebe76be35d04cdde6dcd9f81db091cf46477ef010ad8dddf96cb3b4ce7e5b4e
BLAKE2b-256 checksum
How to use checksums
387f0f8b709954f936d200a59985f1a0a6313b28ae7793e0443ecda0810b2dcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 9, 2026.

Transparency log

Release files / pyhood-0.11.0-py3-none-any.whl

Download URL pyhood-0.11.0-py3-none-any.whl
Size 58.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2e1ba51a2e20851cd2c3b9b4db732dc4140adc0fe43ea5fcc51001ea6fdb244
BLAKE2b-256 checksum
How to use checksums
cc1dc80cfb7db89683cea5d983868fe77d6d679bb71cd0d53f547ff3413cd50f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 9, 2026.

Transparency log

Security for pyhood 0.11.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.

Select from 2 files

Attestation for pyhood-0.11.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 Aug 9, 2026.

Transparency log

A 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.

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