Get help from the marimo community

Updated last month

How do I load javascript libraries within html-wasm?

At a glance

The community member is interested in using html-wasm to deploy marimo and is having trouble accessing data in S3. Since boto3 is not available in Pyodide, they tried using the TS client for AWS S3, but are having trouble loading the client library. The community members discuss alternative approaches, such as using polars or duckdb, but encounter issues with boto3 dependencies. Eventually, the community member finds success using the requests-aws4auth library to access the S3 data. The issue is resolved.

Useful resources
I am very interested in using html-wasm to deploy marimo, and I am currently working through the issue of accessing data in S3. Since boto3 is not available in Pyodide, I was just going to use the TS client for AWS S3. The setup is working fine for running the JS code from within Pyodide (import js, js.eval, etc.). However, since I'm not very experienced with TS, I'm having trouble loading the client library appropriately.

I have:

# Load the AWS SDK for JavaScript
js.self.AWS = await js.eval("""
(async () => {{
import {{ S3Client, GetObjectCommand }} from "@aws-sdk/client-s3";

// Replace with your actual credentials
const client = new S3Client({{
region: "{region}",
credentials: {{
accessKeyId: "{access_key_id}",
secretAccessKey: "{secret_access_key}",
sessionToken: "{session_token}",
}}
}});

return {{ client }};
}})();
""".format(
....

But I get the error: This cell raised an exception: JsException('SyntaxError: Cannot use import statement outside a module')

Any suggestions of how to resolve this?
M
s
17 comments
i dont think what you are trying to do is possible. taking a step back, can you access s3 data with polars or duckdb instead? is it tabular data?
The issue is authentication, I believe. It is tabular data, but I need to provide credentials. Could polars do that?
That would be much better
Yes, ok, this is a much better track
Oh wait, no that won't work because it probably relies on boto3, which is not supported in pyodide
it looks like the s3:// protocol might be busted in polars wasm., but you could try https:// to the s3 url + credentials
The boto issue is a pretty deep one for any of these useful python libraries
Which is what got me going down the route of the JS S3 client
gotcha, yea, i am likely reading the same issues as well right now
The better thing in the long term would be to have a pyodide-compatible version of boto so that native polars (etc.) functions would just work
can you hit your bucket at https://bucketname.s3.amazonaws.com
using polars credentials, or instead just vanilla requests library
requests ended up not working, mostly because it was too hard for me to figure out how to sign the request appropriately. However, I did end up working when I used this - https://pypi.org/project/requests-aws4auth/
Issue resolved!
Add a reply
Sign up and join the conversation on Discord