Skip to main content

File System

Some internal Pyodide file system methods are exposed.

For more info, see the API reference docs.

import { usePython } from 'react-py'

function Codeblock() {
const { readFile, writeFile, mkdir, rmdir ... } = usePython()

function read() {
const file = readFile('/hello.txt')
console.log(file)
}

function write() {
const data = 'hello world!'
writeFile('/hello.txt', data)
}

function createDir() {
mkdir('lib')
}

function deleteDir() {
rmdir('cruft')
}

...
}

You can also use Python to read and write files:

Loading...
note

Files are not shared between instances, each usage of the usePython hook has an independent file system. Files are also not persisted on page reload.

Using multiple files​

You can use Custom Modules to make use of multiple files:

Loading...

You can find the source code for this example here.