Skip to main content

schwab-py: A Charles Schwab API Wrapper

https://img.shields.io/discord/720378361880248621.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2 https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%schwabpy%26type%3Dpatrons&style=flat https://readthedocs.org/projects/schwab-py/badge/?version=latest https://github.com/alexgolec/schwab-py/workflows/tests/badge.svg https://badge.fury.io/py/schwab-py.svg http://codecov.io/github/alexgolec/schwab-py/coverage.svg?branch=master

What is schwab-py?

schwab-py is an unofficial wrapper around the Charles Schwab Consumer APIs. It strives to be as thin and unopinionated as possible, offering an elegant programmatic interface over each endpoint. Notable functionality includes:

  • Login and authentication

  • Quotes, fundamentals, and historical pricing data

  • Options chains

  • Streaming quotes and order book depth data

  • Trades and trade management

  • Account info

I used to use tda-api, how do I migrate?

Now that TDAmeritrade is no more, the old tda-api library will no longer work. Check out our transition guide for instructions on getting started.

How do I use schwab-py?

For a full description of schwab-py’s functionality, check out the documentation. Meawhile, here’s a quick getting started guide:

Before you do anything, create an account and an application on the Charles Schwab developer site. You’ll receive an API key and app secret, which you can pass to this wrapper. You’ll also want to take note of your callback URI, as the login flow requires it. You app must be approved by Schwab before you can use it (this can take several days). You can find more detailed instructions here.

Next, install schwab-py:

pip install schwab-py

You’re good to go! To demonstrate, here’s how you can authenticate and fetch daily historical price data for the past twenty years:

from schwab import auth, client
import json

api_key = 'YOUR_API_KEY'
app_secret = 'YOUR_APP_SECRET'
callback_url = 'https://127.0.0.1:8182/'
token_path = '/path/to/token.json'

c = auth.easy_client(api_key, app_secret, callback_url, token_path)

r = c.get_price_history_every_day('AAPL')
r.raise_for_status()
print(json.dumps(r.json(), indent=4))

Why should I use schwab-py?

schwab-py was designed to provide a few important pieces of functionality:

  1. Safe Authentication: Schwab’s API supports OAuth authentication, but too many people online end up rolling their own implementation of the OAuth callback flow. This is both unnecessarily complex and dangerous. schwab-py handles token fetch and refreshing for you.

  2. Minimal API Wrapping: Unlike some other API wrappers, which build in lots of logic and validation, schwab-py takes raw values and returns raw responses, allowing you to interpret the complex API responses as you see fit. Anything you can do with raw HTTP requests you can do with schwab-py, only more easily.

Why should I not use schwab-py?

As excellent as Schwab’s API is, there are a few popular features it does not offer:

  • While Charles Schwab owns thinkorswim (AKA TOS), this API is unaffiliated with it. You can access and trade against the same accounts as TOS, but some of TOS’s functionality is not supported by schwab-py

  • Paper trading is not supported

  • Historical options pricing data is not available.

What else?

We have a Discord server! You can join to get help using schwab-py or just to chat with interesting people.

Bug reports, suggestions, and patches are always welcome! Submit issues here and pull requests here.

schwab-py is released under the MIT license.

Disclaimer: schwab-py is an unofficial API wrapper. It is in no way endorsed by or affiliated with Charles Schwab or any associated organization. Make sure to read and understand the terms of service of the underlying API before using this package. This authors accept no responsibility for any damage that might stem from use of this package. See the LICENSE file for more details.

Metadata

Release files for schwab-py 1.6.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 schwab-py 1.6.0
File Size Uploaded Provenance Actions
schwab_py-1.6.0.tar.gz 1.3 MB Without provenance Details for schwab_py-1.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for schwab-py 1.6.0
File Interpreter ABI Platform Actions
schwab_py-1.6.0-py3-none-any.whl Python 3 none any Details for schwab_py-1.6.0-py3-none-any.whl

Total release size: 1.4 MB

Release files / schwab_py-1.6.0.tar.gz

Download URL schwab_py-1.6.0.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
985ed73bf63a8747e36d0ee0aaeed00b01b7d9cef810bb6614604a4c3c551162
BLAKE2b-256 checksum
How to use checksums
b65bbb0a9908cce8d7d9b9525484fd05698aa4c06a926bb5fd5a3f150ec3e7cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.19

Release files / schwab_py-1.6.0-py3-none-any.whl

Download URL schwab_py-1.6.0-py3-none-any.whl
Size 54.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72914093af760e7d6efc1b3836c51a1f974a6518fec002694448b3aa037c84b1
BLAKE2b-256 checksum
How to use checksums
6291f0eed08437712f1f440bbd89e44a5cd78f8d54ca037e6aaa5bfa88739fa4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.19

Security for schwab-py 1.6.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

1.6.0 This release

2 release files No provenance

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