- Read data from the local file system
- Read data from the network
- Input data from the user
- Create data inside your application
In addition to my other articles, ten so far, I am planning several more articles that cover in detail each area that I mention in this article.
Read data from the local file system
Browser applications are not permitted to directly access the user’s local file system. All requests to read or write data require making an API request to the browser. The browser requires the user to have performed a gesture such as clicking a button. There are two primary APIs: FileReader and File System Access API. I wrote a multipart series on accessing the local file system using these APIs: Part 1 and Part 2.
Read data from the network
Browser applications cannot open network sockets. All network requests are performed by the Fetch API. This means all network requests must be one of the HTTP GET, POST, PUT, etc styles of requests. This is the norm for REST APIs. You cannot open network connections to services such as databases. Those services must provide a REST API to handle browser requests.
PyScript does offer a wrapper PyFetch but I find that implementation not useable for REST API because the HTTP response headers are not returned which is very important. I am planning an article on how to use fetch() to make HTTP requests.
Input data from the user
PyScript applications cannot request the user to type characters in response to Python input type of functions. PyScript applications must use HTML DOM elements to create a GUI that data is entered into. Then the application can read the data from those elements. See this link: User input and controls
Create data inside your application
Once your PyScript application is loaded and running, your application can create data and then store it using several methods:
- POST the data back to the server using the Fetch API
- Save the data on the local file system in response to the user making a gesture such as clicking a button.
- Save data to the browser’s virtual file system – this is not persistent and data is lost on page refresh
- Save data to the browser’s Storage, such as Local Storage and IndexedDB. See this link: Web Storage API.
- Pyscript: Files and File Systems – Part 1
- Pyscript: Files and File Systems – Part 2
- Other articles that I have written on Pyscript
- File System Access API
- Fetch API
- PyFetch API
- User input and controls
- Web Storage API
- Progressive Web Apps (PWAs)
- Cache Storage
I design software for enterprise-class systems and data centers. My background is 30+ years in storage (SCSI, FC, iSCSI, disk arrays, imaging) virtualization. 20+ years in identity, security, and forensics.
For the past 14+ years, I have been working in the cloud (AWS, Azure, Google, Alibaba, IBM, Oracle) designing hybrid and multi-cloud software solutions. I am an MVP/GDE with several.