Announcing schwab-py v2.0
Reviving Regular Maintenance
After a prolonged hiatus for good reasons, I promise, I am
returning to actively maintaining schwab-py! In the interim, we’ve seen good
developments, like the community developing some very interesting forks and
submitting some very important requests, as well as some bad developments, like
deprecation warnings and bugs creeping in. I am now actively working through the
outstanding issues with the library, as well as incorporating some of the
interesting ideas suggested and implemented by community members.
V2 Transition Timeline
Some of the changes I am exploring are unfortunately breaking changes. For
instance, the migration from the deprecated httpx to the supported
httpx2 results in a different exposed exception hierarchy, which will cause
existing code to break. In order to preserve compatibility with existing code,
these new changes will be released as a 2.x version series.
In order to minimize the impact on users, we will implement a transition plan:
All
1.xreleases will feature a deprecation warning admonishing users to either prepare to transition to 2.0 or pin their versions to<2.0in their package managers.2.0will be made available as an extended series ofalphaandbetareleases prior to release, effectively turning it into an optional release for a time. During this prerelease period, the interface will be subject to change.Once the interface stabilizes, a series of one or more
2.0release candidates will be released with the finalized interface.The final
2.0rc(x)release candidate will be released as2.0no less than 90 days after the first1.xrelease featuring the deprecation warning, and no less than 14 days after the final2.0release candidate. This way, users who are still on1.xhave an opportunity to learn about and prepare for the upcoming upgrade, and users following along with the development of2.0can adjust to the stable interface.All development will be accompanied by frequent updates in the support channel on the project discord server.
Compatibility Changes
This section lists the substantive differences between 1.x and 2.0.
httpx replaced with httpx2
All HTTP is now performed by httpx2, the
actively maintained successor to httpx. Response objects, status codes,
timeouts, and client configuration are API-compatible, so most users will
notice no difference. However, httpx and httpx2 define separate class
hierarchies, so code that references httpx types directly will need
updating:
except httpx.HTTPError(and otherhttpxexception types) will not catch errors raised by this library. Update exception handling to usehttpx2exceptions.isinstance(response, httpx.Response)checks andhttpx.Responsetype annotations will fail against our return values. Usehttpx2.Response.The
httpxlogger is renamedhttpx2; update logging configuration accordingly.
Websocket implementation updated
Streaming now uses websockets.asyncio (the maintained implementation)
instead of the deprecated websockets.legacy. This is transparent for most
users, but arguments passed via websocket_connect_args to
schwab.auth.easy_client() are forwarded verbatim to
websockets.asyncio.client.connect, whose signature differs from the legacy
connect:
extra_headersis renamedadditional_headerscreate_protocolis renamedcreate_connectionwith a different signatureread_limitis removed
New options are also available, including proxy, reconnect_delays,
and process_exception. See the websockets asyncio client documentation
for the full signature.
Prices must be strings
OrderBuilder.set_price, OrderBuilder.set_stop_price, and the order
templates that call them now require prices as strings. Passing float
(or any other non-string value) raises ValueError; the deprecated
truncate_float conversion path is removed, along with the warning it
emitted. Callers previously relying on float conversion must format prices
themselves — e.g., f'{price:.2f}'.
Strings that do not parse as numbers continue to pass through unvalidated,
but strings that parse to non-finite values ('nan', 'inf',
'-inf', overflow values like '1e999') now raise ValueError since
they can never represent a real price. copy_price and
copy_stop_price still bypass validation as before.
AI Disclosure
In keeping with the general tendency in our industry, development of
schwab-py is now performed substantially using AI tools. These tools have
proven incredibly useful, and I’ve already been able to implement tasks in days
which I previously expected me to take weeks. I expect these tools will allow me
to create a more correct, feature-rich, and useful library than I would have
been able to deliver otherwise.
On the topic of correctness: AI thrives with concrete and specific feedback, and to that end I am implementing a substantial functionality testing regime based on placing real API calls against my personal Charles Schwab accounts. You may inspect these tests in the livetests directory of the codebase. If you spot anything suspicious, incorrect, or incomplete, please let me know in the Discord server.