1

I am creating a web application using python with the brython.js library and for my application I need to import the bs4 library and the requests library but I don't know how.

Any idea?

<script type="text/python">
from browser import document
import bs4 #doesn't work
import requests #doesn't work
</script>
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Blackjack
  • 1,322
  • 1
  • 16
  • 21
  • Does this answer your question? [How to import library using Brython](https://stackoverflow.com/questions/40001634/how-to-import-library-using-brython) – Karl Knechtel Feb 11 '23 at 20:24

2 Answers2

1

Like in standard Python, you can install modules or packages Python in your application by putting them in the root directory, or in directories with a file __init__.py.

Note: that modules must be encoded in utf-8; the encoding declaration at the top of the script is ignored.

For instance, the application can be made of the following files and directories:

app.html
brython.js
brython_modules.js
brython_stdlib.js
index.html
users.py
utils.py
+ app
    __init__.py
    records.py
    tables.py

And you can run the imports:

import users
import app.records
DogCoding
  • 64
  • 4
  • This is just a copypaste from official manual and it's very unclear https://brython.info/static_doc/en/import.html – megapro17 Jun 19 '21 at 13:24
1

You can use ajax, a function in the browser module.

from browser import ajax
def read(req):
    print(req.text)
ajax.get('https://example.com', oncomplete=read)

Note: You may face issues regarding CORS

ajskateboarder
  • 379
  • 4
  • 11