Schwab API in Python: schwab-py vs Schwabdev, Setup to First Order

You can trade a Schwab brokerage account from Python in 2026. Schwab has no official Python SDK; what exists is the Schwab Trader API, an HTTP interface with OAuth sign-in, and two community libraries that wrap it, schwab-py and Schwabdev. Either one gets you from a developer-portal app to a placed order in an afternoon, once Schwab has approved the app. This page is the practical route: what to set up before writing code, how the two libraries differ, what the first run looks like with each, the order payload Schwab expects, how to keep a script alive past the 30-minute access token and the 7-day refresh token, and the errors you will meet in the first week. Three facts shape every design decision and are worth knowing before you pick a library: the refresh token dies after seven days and only a browser login revives it; there is no sandbox, so your first order is a live order in a live account; and the API allows 120 non-order requests a minute, so quotes come from the stream, not a loop.
What this page is not: a replacement for the Schwab Trader API explainer, which covers what the API can and cannot do and the lessons from 294 live automated orders, or for the developer portal guide, which covers registration and the approval wait in detail. It also does not reach thinkorswim; thinkorswim has no API of its own, and Python code reaches the account that thinkorswim trades, not the platform's studies, alerts or paperMoney. Library facts below are from each project's documentation as read on November 15, 2026, with the links; the behaviors of the API itself, tokens, limits and rejections, are what JorgAI's own Schwab integration runs into every day. We have not run either library's code for this page and say so where it matters.
Before any code: the developer portal
Both libraries need the same five things from developer.schwab.com, and every one of them is a place first apps get stuck; the detail is on the developer portal guide.
A developer account under the same email as your Schwab brokerage login. Schwabdev's setup guide says so explicitly, and the API only sees accounts linked to that identity.
Access to the Trader API - Individual product, then an app with both products attached: Accounts and Trading Production and Market Data Production. Without the second one, quotes and price history return 401 Client not authorized, the most common first-day error in Schwabdev's troubleshooting page.
A callback URL that is HTTPS and local, typed exactly as your code will send it. schwab-py recommends https://127.0.0.1:8182 with the port, because its login flow runs a small local HTTPS server on that port to catch the redirect; Schwabdev's default is https://127.0.0.1 without a port, because it has you paste the redirected address back into the terminal instead. A trailing slash that does not match produces an Access Denied page after sign-in.
An order limit chosen at registration, from 0 to 120 order requests a minute. Both communities recommend 120; a rules-based script that places a handful of orders a day never approaches it.
Patience. A new app, and every edited app, sits at Approved - Pending for days before it reads Ready For Use, and keys from a pending app fail with a 500 Whitelabel error page rather than a clear message. Create the app before you write the code so the review runs while you build, and put the app key and secret in a .env file that your .gitignore excludes. Schwabdev's guide adds one more step: the account must have thinkorswim enabled, which happens the first time you log in to a thinkorswim platform, or some order calls fail.
schwab-py vs Schwabdev at a glance
| schwab-py | Schwabdev | |
|---|---|---|
| Maintainer and license | Alex Golec, MIT | Tyler Bowers, MIT |
| Latest release (PyPI) | 1.5.1, June 30, 2025 | 4.0.0, August 9, 2026 |
| Python required | 3.10 or newer | 3.11 or newer |
| GitHub, November 15, 2026 | 485 stars, 57 open issues, last push November 2026 | 902 stars, 0 open issues, last push August 2026 |
| Sign-in flow | Opens a browser and catches the redirect with a local HTTPS server on the callback port (127.0.0.1 only); a manual copy-paste flow and a token-generator script exist for machines without a browser | Prints a link, you sign in, approve, pick accounts, then paste the address bar back into the terminal; a call_on_auth hook lets you automate that step |
| Where tokens live | A JSON file at the token_path you choose; refreshed tokens are written back to it | A SQLite database, ~/.schwabdev/tokens.db by default, optionally encrypted with a Fernet key |
| Access-token refresh | Automatic | Automatic, checked on each request |
| Orders | Template functions (equity_buy_limit and friends) and an OrderBuilder; one_cancels_other and first_triggers_second for composites | You pass Schwab's order JSON as a Python dict; preview_order checks it before placing |
| Market data | get_quote, get_quotes, get_price_history with per-interval helpers, option chains, a streaming client | quotes, quote, price_history, option_chains, movers, market_hours, a Stream and StreamAsync |
| Async | A keyword on the client constructor | A separate ClientAsync, with parsed responses optional |
| Documentation | Read the Docs, with a getting-started, authentication and order-template guide | A docs site plus docs/examples (api_demo.py covers every call) and a troubleshooting page |
The practical difference is the sign-in and the orders. schwab-py does the OAuth dance in the browser for you and gives you typed order templates, which is the gentler first day on a laptop and the stricter path to a correct order. Schwabdev asks you to paste one URL on first run, stores tokens in a database that several processes can share, and hands you Schwab's raw order JSON, which is more typing and also exactly what you will read back from the API when you inspect an order someone placed in thinkorswim. Schwabdev shipped a major version in August 2026 and lists no open issues; schwab-py's last release is from mid-2025 with commits as recent as this month and a longer open-issue list. Both work. If you expect to run on a headless server, read the token section below before choosing, because the 7-day sign-in is the part no library can automate.
First run with schwab-py
Install it into a virtual environment with pip install schwab-py; the import name is schwab. The authentication guide recommends one entry point, easy_client, which takes your api_key, app_secret, callback_url and a token_path. On the first call there is no token file, so it opens a browser, you sign in at Schwab and approve the app, Schwab redirects to https://127.0.0.1:8182, the library's local server catches the code and writes the token file. Your browser will warn about a self-signed certificate on that local address; the guide says to proceed after checking the address matches your callback. On every later run easy_client finds the file and skips the browser. Two companions matter for servers: client_from_manual_flow, which walks you through copying URLs by hand where no browser can open, and the schwab-generate-token script, which creates a token on one machine for use on another; the guide's rule is never to use one token on two machines at once, and to delete the original after copying it.
With a client in hand, get_account_numbers returns each account's hash value, the identifier every account call uses instead of the account number. get_quote and get_quotes return the quote JSON; get_price_history_every_day and its minute-level siblings return bars. An order is built from a template in schwab.orders.equities, such as equity_buy_market(symbol, quantity) or equity_buy_limit(symbol, quantity, price), optionally chained with set_duration and set_session from schwab.orders.common, then passed to place_order(account_hash, order_spec). A successful placement returns a status code and usually no body; the guide's advice is to assert on the status code so a rejected order raises instead of passing silently. Composite orders use one_cancels_other and first_triggers_second from schwab.orders.common on built orders, and the order templates page lists the equity and option templates; stop and stop-limit equity orders are not among the templates, so those go through the OrderBuilder.
First run with Schwabdev
Install with pip install schwabdev on Python 3.11 or newer; macOS users must also run Python's Install Certificates command or the first HTTPS call fails with a certificate error, which the setup guide calls out. Create the client with schwabdev.Client(app_key, app_secret, callback_url); the first run prints a sign-in link, you log in at Schwab, agree to the terms, select the accounts to share, and paste the address bar's URL back into the terminal. Tokens go into a SQLite file, ~/.schwabdev/tokens.db by default, which is why several scripts can run at once against one token set; pass an encryption key to encrypt it. The client checks and refreshes the access token on every request, so there is no background thread to keep alive.
linked_accounts returns the account numbers and hash values; account_details with fields set to positions returns balances and holdings; account_orders takes a date range. Market data comes from quotes, quote, price_history, option_chains, movers and market_hours. Orders are plain dictionaries in Schwab's own shape, placed with place_order(account_hash, order); the order id comes back in the response's Location header rather than the body, unless the order filled instantly, and preview_order runs the same payload through Schwab's validation without placing it, which is the closest thing to a sandbox the API offers. The docs state the order limits as 120 orders a minute and 4,000 a day, and that fractional orders are not supported.
The order Schwab expects
Whichever library you use, the payload that reaches Schwab is the same JSON, and reading it once saves a week of 400 errors. A single equity order carries orderType (MARKET or LIMIT, with price for a limit), session (NORMAL for the regular session), duration (DAY or GOOD_TILL_CANCEL), orderStrategyType SINGLE, and an orderLegCollection with one leg: instruction BUY or SELL, a whole-number quantity, and an instrument with the symbol and assetType EQUITY. A conditional order sets orderStrategyType to TRIGGER and nests the follow-up order in childOrderStrategies, which is how a bracket is expressed. Options use the same leg structure with assetType OPTION and Schwab's 21-character option symbol, the underlying padded to six characters followed by the expiry, call or put, and the strike. Indexes take a dollar sign prefix. Quantities are whole shares: Schwab's API does not place fractional orders, and the Stock Slices you see in the Schwab app are not reachable from it.
Schwabdev's orders page gives the full set of worked payloads, and its advice when a shape is missing is the one we would give: place the order once in thinkorswim, read it back with order_details, and copy the structure. For what the API rejects in practice, our page on 294 live Schwab orders has the only rejection our integration has seen in volume, Could not resolve instrument on symbols Schwab's order desk did not recognize, and the latency from signal to fill.
Keeping it alive: tokens, limits and the weekly login
The access token lasts 30 minutes and both libraries renew it for you. The refresh token lasts seven days and nothing renews it except a human signing in at Schwab in a browser; the libraries agree, our integration confirms it, and Schwab has offered no alternative. schwab-py's guide says an expired refresh token shows up as an invalid_client error on the next refresh, that the fix is to delete the token file and sign in again, and that the sensible pattern is to recreate the token on a schedule such as before the market opens each week; its easy_client even deletes and recreates a token older than max_token_age, 6.5 days by default, so the login happens on your terms rather than mid-session. Schwabdev's troubleshooting page lists the same refresh-token failure and, under the entry "Refresh token expiring in 7 days is too short," offers the fix "I know." Plan for it: a script that trades unattended needs a person at a browser once a week, a calendar reminder, and a safe state to fall into when the token dies, which for an open position means the exits already sitting at the broker. How our worker handles the same lifecycle is written up separately: refresh at 20 minutes, serialize refreshes per account, pause and notify when the 7-day token goes.
Rate limits are 120 non-order requests a minute per app, with the order limit set at registration. Schwabdev's API page is blunt: do not poll market-data endpoints in a loop, use the stream. Both libraries ship a streaming client for level-one quotes and the rest. Keep one token set per machine, never commit the .env or the token file, treat the token file as you would your Schwab password, because anyone holding it can act in the account, and log every request and response, since the API's error bodies are the only diagnostics you get.
Testing when there is no sandbox
The Trader API has no paper environment; the same base URL serves live accounts and the account hash in the call decides which one is touched. paperMoney inside thinkorswim cannot be reached by software. So the testing sequence is the one every careful builder arrives at: run read-only for a week, printing account details, quotes and the orders you would have placed; run preview_order (Schwabdev) or build the order and inspect it without placing it (schwab-py) against the real account to catch payload errors; then place a one-share limit order away from the market and cancel it, which exercises place, read and cancel for pennies of exposure; then trade at the smallest size that is meaningful for a month before scaling. If you want to rehearse the rules themselves on simulated money first, do it on a broker whose API has a paper environment and bring the rule set to Schwab afterwards; how to automate trading in a Schwab account covers that sequence.
The errors you will meet in the first week
| What you see | What it usually means | What to do |
|---|---|---|
| 401 Client not authorized | The app is missing one of the two API products, or the access token expired | Add both products in the app's settings; force an access-token refresh (Schwabdev: update_tokens with force_access_token) |
| 500 with a Whitelabel Error Page, or "We are unable to complete your request" | The app is still Approved - Pending | Wait for Ready For Use; nothing in your code fixes this |
| Access Denied page after signing in | The callback URL your code sent does not match the app's, usually a trailing slash | Make the two identical, character for character |
| assertion_rejected or 401 during the first login | App not yet approved, or keys from a different app | Check the app status and the key pair |
| invalid_client on a refresh | The 7-day refresh token has expired | Delete the token file or database entry and sign in again; schedule the weekly login |
| unsupported_token_type on a refresh | The refresh token was replaced elsewhere, for example by a login on another machine | Use one token set per machine; re-authenticate on this one |
| SSL: CERTIFICATE_VERIFY_FAILED on macOS | Python's certificates were never installed | Run the Install Certificates command that ships with Python |
| 404 Not Found on a symbol | Wrong symbol format | Indexes need a dollar sign prefix; options use the 21-character symbol; check the symbol exists on thinkorswim |
| Could not resolve instrument on an order | Schwab's order desk does not recognize the symbol | Our 294-order sample saw 18 of these in one week; drop the symbol rather than retry |
| Body buffer overflow on a chain request | The response is too large | Narrow the option chain with contract type, strike range or expiry parameters |
Build it, or connect through a platform
Writing your own Schwab client is a reasonable weekend if you want full control and are willing to own the scheduler, the token lifecycle, the order reconciliation and the uptime, and to test with real shares because nothing else is available. The weekly browser login is the one chore no amount of code removes, and it is the reason most hobby bots on Schwab go quiet by the second month. The alternative is a platform registered with Schwab on the commercial tier, where you sign in to Schwab once through the platform's hosted callback, never visit the developer portal, and set the rules instead of writing them. JorgAI is one of those: the connection is made on Schwab's own sign-in page with access you can revoke at Schwab, the worker refreshes the access token every 20 minutes, and when the 7-day token dies it pauses trading and emails you to reconnect; position caps, a daily spend cap, stops and targets sit as orders at the broker, and every candidate it declines is logged with the reason. The Schwab page has the connection steps and the settings glossary defines every cap and exit; to watch the rules run on a simulated account first, start on the free plan.
Quick answers
Is there an official Schwab Python SDK?
No. Schwab publishes the Trader API, an HTTP interface with OAuth sign-in, on its developer portal. schwab-py and Schwabdev are community libraries under the MIT license that wrap it; neither is affiliated with or endorsed by Schwab.
schwab-py or Schwabdev: which should I use?
Both reach the same API. schwab-py does the browser sign-in for you and offers typed order templates; Schwabdev uses a paste-the-URL sign-in, stores tokens in a shareable SQLite database, takes Schwab's raw order JSON, and shipped version 4.0.0 in August 2026 with no open issues at the time of writing. Pick schwab-py for a laptop and typed orders, Schwabdev for several processes sharing one token set or for reading and writing Schwab's native payloads.
Does the Schwab API have a sandbox or paper trading?
No. Every order is live. Schwabdev's preview_order validates a payload without placing it, and a one-share limit order away from the market, then cancelled, is the cheapest full test. paperMoney exists only inside thinkorswim and cannot be reached by software.
Why does my script stop working after a week?
The refresh token expires seven days after the sign-in and only a browser login issues a new one. Schedule the login before the week's first session, use schwab-py's max_token_age or Schwabdev's token checks to catch it early, and make sure open positions have their exits at the broker when it happens.
Can I run it on a server or in the cloud?
Yes, with the login done elsewhere. schwab-py's manual flow and its token-generator script create a token on a machine with a browser for use on one without; Schwabdev's call_on_auth hook lets you supply the callback URL from another process. One token set per machine, and the weekly login still needs a person.
Does the Schwab API support fractional shares?
No. Orders are whole shares; the Stock Slices feature in Schwab's app is not available through the API.
What are the rate limits?
120 non-order requests a minute per app, and an order limit you choose when registering the app, up to 120 a minute; Schwabdev's docs also cite 4,000 orders a day. Quotes for more than a few symbols belong on the streaming client.
How we put this together. Library facts are from schwab-py's documentation (getting started, authentication and client creation, client, order templates) and Schwabdev's documentation (setup guide, client, API calls, orders, troubleshooting) and the api_demo.py example in its repository, all read on November 15, 2026; release versions and dates from PyPI and PyPI; stars, open issues and last-push dates from the GitHub API for alexgolec/schwab-py and tylerebowers/Schwabdev the same day. We did not run either library to write this page. The API behaviors described, token lifetimes, request limits, the absence of a sandbox, whole-share orders and the rejection messages, are what JorgAI's Schwab integration meets in production, written up with sources on the Trader API, developer portal, token and fill pages linked above. Schwab's developer portal blocks automated readers, so portal wording is cited through those pages and the libraries' guides.
This article describes developer tools and is not investment advice or a recommendation of any broker or security. JorgAI is software that carries out the rules you set in your own brokerage account; it is not an investment adviser. Trading involves risk of loss. schwab-py and Schwabdev are independent open-source projects; Charles Schwab & Co., Inc. is not affiliated with JorgAI or with either project.
More in AI & Technology
Keep reading
Let the AI do the trading.
Set it up in minutes. 7 day free trial on Starter, Plus and Pro.
Get started freeGet the weekly market read and new tools by email
One email a week: what moved, what the data says, and the next free tool when it ships. No spam, unsubscribe in one click.
More from the blog
Every other post, newest first
247 more posts
Stops, targets and a daily loss limit, enforced for you.
JorgAI runs the rules you set inside your own brokerage account. Zero withdrawal permissions, disconnect anytime.
Showing 18 of 247. Keep scrolling.




















