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

feat: add stream_href method #123

Merged
merged 1 commit into from
Nov 21, 2023
Merged

feat: add stream_href method #123

merged 1 commit into from
Nov 21, 2023

Conversation

jkeifer
Copy link
Member

@jkeifer jkeifer commented Nov 17, 2023

Related issues and pull requests

  • n/a

Description

I have a case where I am using read_href, but can significantly decrease memory usage if I use the chunks as they are downloaded rather than waiting for the the complete byte stream from read_href. Seeing that read_href is concatenating a stream, this change simply splits the chunked downloading from read_href into a new method stream_href, which read_href uses internally.

Checklist

  • Add tests
  • Add docs
  • Update CHANGELOG

@jkeifer jkeifer requested a review from gadomski as a code owner November 17, 2023 23:52
@codecov-commenter
Copy link

codecov-commenter commented Nov 17, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5683121) 79.73% compared to head (319325b) 79.79%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #123      +/-   ##
==========================================
+ Coverage   79.73%   79.79%   +0.06%     
==========================================
  Files          16       16              
  Lines         982      985       +3     
==========================================
+ Hits          783      786       +3     
  Misses        199      199              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jkeifer
Copy link
Member Author

jkeifer commented Nov 18, 2023

Actually, I may have jumped the gun on this one. If it isn't something that you want to support as part of the public API without a solid use-case then please leave this unmerged for a short while until I re-confirm the need.

Copy link
Member

@gadomski gadomski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the name change, we should also add a stac_asset.blocking.open_href.

src/stac_asset/_functions.py Outdated Show resolved Hide resolved
@jkeifer
Copy link
Member Author

jkeifer commented Nov 21, 2023

I'm not sure there's a particularly elegant way to make a blocking version of open_href. The fundamental problem is asyncio.run() will synchronously execute a coroutine, but open_href is different in that it is returning an AsyncIterable which itself needs to be, well, asynchronously iterated. As far as I understand it, you can't do async iteration without running in an event loop.

I did find a snippet on SO that shows how to do this: https://stackoverflow.com/a/55164899. I don't know how you feel about it, but I wouldn't want to maintain something like that in this lib--if a user really needs to use open_href in sync code I would say they can take on a solution like that.

@gadomski
Copy link
Member

Nope, makes a lot of sense, thanks for pointing that out.

@gadomski gadomski merged commit 7ef430d into main Nov 21, 2023
11 checks passed
@gadomski gadomski deleted the jak/stream-href branch November 21, 2023 18:31
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

Successfully merging this pull request may close these issues.

3 participants