-
Notifications
You must be signed in to change notification settings - Fork 76
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
Document Pyodide/PyScript usage. #2262
Comments
How do we load from a URL easily? We marked #1566 as low priority, but maybe this now moves it up the stack? |
#1566 won't help here, unless we specifically write it to detect it is running in Pyodide. This is because you can't open sockets like normal Python due to the web security model, so modules like |
Ah, yes, of course. I forgot about |
I don't that the faffing there is so bad. Jupyterlite is always an option. |
There is now a pyodide.http import tempfile
from pyodide.http import pyfetch
import micropip
await micropip.install("tszip")
import tszip
async def load_remote_tree_file():
# URL of the tree file, using corsproxy to avoid CORS issues
url = "https://corsproxy.io/https://github.com/tskit-dev/tutorials/raw/refs/heads/main/data/viz_ts_selection.trees"
# Fetch the file using pyfetch
response = await pyfetch(url)
# Check if the request was successful
if response.status == 200:
# Get the array buffer from the response
# Save to a temporary file
with tempfile.NamedTemporaryFile() as f:
data = await response.bytes()
f.write(data)
# Load the tree file with tszip
ts = tszip.load(f.name)
print(f"Successfully loaded tree sequence with {ts.num_trees} trees and {ts.num_samples} samples")
return ts
else:
print(f"Failed to fetch file: Status code {response.status}")
return None
ts = await load_remote_tree_file()
print(ts.first().draw_text()) For tutorial material, I presume we would serve the pyodide / jupyterlite instance from the same location as the |
Advertise possibilities, advise of limitations and give an example of loading a ts from a URL and plotting it.
The text was updated successfully, but these errors were encountered: