Usage¶
littlefs-python offers three interfaces to the underlying littlefs library:
A C-Style API which exposes all functions from the library using a minimal wrapper, written in Cython, to access the functions.
A pythonic high-level API which offers convenient functions similar to the ones known from the
osstandard library module.A command line tool, available as
littlefs-python. See Command Line Interface for more information.
Both API’s can be mixed and matched if required.
C-Style API¶
The C-Style API tries to map functions from the C library to python with as little
intermediate logic as possible. The possibility to provide customized read(),
prog(), erase() and sync() functions to littlefs was a main goal
for the api.
All methods and relevant classes for this API are available in the littlefs.lfs
module. The methods where named the same as in the littlfs library, leaving out the lfs_
prefix. Because direct access to C structs is not possible from python, wrapper classes
are provided for the commonly used structs:
LFSFilesystemis a wrapper around thelfs_tstruct.LFSFileis a wrapper around thelfs_file_tstruct.LFSDirectoryis a wrapper around thelfs_dir_tstruct.LFSConfigis a wrapper around thelfs_config_tstruct.
All these wrappers have a _impl attribute which contains the actual data. Note that
this attribute is not accessible from python.
The LFSConfig class exposes most of the internal fields from the
_impl as properties to provide read access to the configuration.
Pythonic API¶
While the pythonic API is working for basic operations like reading and writing files, creating and listing directories and some other functionality, it’s by no means finished. Currently the usage is best explained in the Examples section.