How to import web3 into pyscript?

Viewed 74

Im new to pyscript and i wan to use web3.py in my index page

This here is my index.html page

<body>
   
   <py-env>
      - web3
   </py-env>
 <py-script >
   import web3

   bsc = 'https://bsc-dataseed.binance.org/'    
   web3 = Web3(Web3.HTTPProvider(bsc))
   print(web3.isConnected())
 </py-script>

</body>

When I run this file the page is only loading but nothing is being displayed on my site.

I have installed web3 and I have tried to import it as

<py-env>
      - web3==5.30.0
   </py-env>

same error as above

1 Answers

The package web3 is not compatible with PyScript because the package depends on websockets which is not a pure Python 3 wheel and cannot be loaded by pyodide.

Any package that depends upon the TCP Sockets I/O APIs is not supported within a browser due to sandbox security limitations.

The solution is to ask the web3 team to update their package, or perhaps do the updates yourself and contribute the changes.

Related