Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow session to be cached to disk #53

Closed
tristanpenman opened this issue Mar 10, 2024 · 6 comments
Closed

Allow session to be cached to disk #53

tristanpenman opened this issue Mar 10, 2024 · 6 comments

Comments

@tristanpenman
Copy link
Contributor

Thanks for your work on this library. I was so glad to find it!

I'm currently using the library in a few different ways - some smaller scripts, but also a long-running server. In both cases, it has been useful to cache the session data between runs, to avoid the login step. The way I've implemented this is to write the cookies and headers to a JSON file, and to read those before attempting to log in.

I've recently rebased my changes against @4rumprom's async branch, and you can see the diff here:
https://github.com/4rumprom/schwab-api/compare/Async...tristanpenman:schwab-api:cache-session?expand=1

If this is something that you would be interested in supporting, I can raise a PR once @4rumprom's changes are merged.

@4rumprom
Copy link
Contributor

That would be really cool actually as it could help structure my code a bit better!

@itsjafer
Copy link
Owner

I tried implementing this a while ago and found it didn't persist correctly. How long can you keep login data cached, in your testing? I'd love to be able to make the login step a one-time cost of using the API

@tristanpenman
Copy link
Contributor Author

I believe it will depend on the user's individual security settings in the Charles Schwab portal. I'll take a closer look at the contents of the cookies to see that is exposed in any way. Otherwise I would probably just use a periodic refresh of the token, based on the minimum web session timeout.

@itsjafer
Copy link
Owner

Hi @tristanpenman, I've merged in the async changes from @4rumprom's PR. I would love it if you could create a PR for persisting login data!

@tristanpenman
Copy link
Contributor Author

I've raised a draft PR for this: #56

I'll do some more testing with my particular use cases, with a focus on error cases. Error handling is pretty much untested right now, so expect one or two more commits on the basis of that testing 😅

@itsjafer
Copy link
Owner

Thank you for your contribution @tristanpenman! Your PR has been merged and should be available in v0.4.1 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants