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

Web3 on pyodide #3088

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

joemarshall
Copy link

This is the basic patch for it to be possible to build and run web3.py on webassembly using pyodide.

It works for synchronous http only right now. Calls to async or websockets functions will raise exceptions,

Right now it is at the point where:

from web3 import Web3, HTTPProvider

w3 = Web3(HTTPProvider('https://goerli.infura.io/v3/<apikey>'))
w3.is_connected()
w3.eth.get_block("latest")

should work

I built a pyodide distribution with it in here:

https://joemarshall.github.io/web3_py_on_web/dist/console.html

Still todo on this is bits that are outside web3.py itself:

  1. Figure out how to package this easily (I had a load of hassle running micropip.freeze to make the pyodide lock file that I use so that it loads nicely on import)
  2. Build in a jupyterlite based notebook environment so that one can store private keys etc.

#3056

@joemarshall joemarshall marked this pull request as ready for review September 22, 2023 13:04
@joemarshall
Copy link
Author

@wolovim

Once this PR in pyodide is in pyodide/ we'll have an easy way to build this for webassembly and then create a pyodide environment with all of web3 available, so it is probably worth merging the changes here in now if they look okay?

@wolovim
Copy link
Member

wolovim commented Sep 22, 2023

Once this PR in pyodide is in pyodide/ we'll have an easy way to build this for webassembly and then create a pyodide environment with all of web3 available, so it is probably worth merging the changes here in now if they look okay?

apologies for letting this PR go without comment @joemarshall. thank you for the initiative. talked to the team and we agreed that being able to host a learning environment in a browser would be great, though likely not something we can invest much time in before end of year. there was hesitation about including the code in the main branch, so current thinking is to try maintaining this in a separate branch.

i didn't follow your comment exactly. can you clarify? by all of web3, are you including aiohttp and websockets? planned adding and removing of stubs would further support this living on a different, experimental branch.

@joemarshall
Copy link
Author

i didn't follow your comment exactly. can you clarify? by all of web3, are you including aiohttp and websockets? planned adding and removing of stubs would further support this living on a different, experimental branch.

I think sync http right now, but you're right - planning for experimental branch to remove stubs as things get ported in pyodide would make sense to me.

@wolovim wolovim self-assigned this Oct 11, 2023
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.

None yet

2 participants