Filesystem
Some PalmSens devices, like the EmStat 4, EmStat Pico, Sensit Wearable, and Nexus) have an internal filesystem where they can store measurements (.dmeas files), and other data, e.g. generated by MethodSCRIPT. PyPalmSens provides a file-system-like interface to browse, read, write, and delete files on the connected instrument through pypalmsens.DeviceFileSystem. Asynchronous workflows are supported via pypalmsens.DeviceFileSystemAsync.
Example:
>>> import pypalmsens as ps
>>> with ps.connect() as manager:
... fs = ps.DeviceFileSystem(manager)
... print(fs.listdir())
[DevicePath('Measurements/17-07-2026/LSV-10-00-28-1.dmeas'), DevicePath('Measurements/04-08-2026/LSV-16-02-20-0.dmeas'), ...]
For more information how to use these classes, see the documentation here.
Classes:
pypalmsens.DevicePath
A path object representing a file or directory on the device.
Subclasses pathlib.PurePath to provide POSIX-style path semantics for PalmSens device filesystem paths.
pypalmsens.DeviceFileSystem
DeviceFileSystem(instrument_or_manager: Instrument | InstrumentManager)
Provide a file-system-like interface to a PalmSens device.
Allows browsing, reading, writing, and deleting files on the connected instrument as if they were entries in a local directory tree.
Note that if not used as a context manager, the manager must have an active connection with the device.
Parameters:
-
(instrument_or_managerInstrument | InstrumentManager) –An instrument instance or an existing
InstrumentManager. If an instrument is passed, a new manager will be created.
Methods:
-
__truediv__–Join a path component to the root directory.
-
close–Close connection with device filesystem.
-
delete_all_files–Delete all files on the device.
-
exists–Check whether a path exists on the device.
-
free–Return free space on filesystem.
-
iterdir–Iterate over entries in a device directory.
-
listdir–List all entries in a device directory.
-
load_measurement–Load measurement from path on device.
-
open–Open connection with device filesystem.
-
read_text–Read the content of a file as text.
-
remove–Remove a file from the device.
-
size–Return total size of filesystem.
-
size_of–Get the size of a file.
-
timestamp_of–Get the modification timestamp of a file.
-
walk–Generate file names by walking the directory tree starting from a device directory.
Attributes:
-
root(DevicePath) –Return path of root directory.
Source code in src/pypalmsens/_instruments/filesystem.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
root
property
root: DevicePath
__truediv__
__truediv__(path_str: str) -> DevicePath
Join a path component to the root directory.
Source code in src/pypalmsens/_instruments/filesystem.py
118 119 120 | |
close
close()
Close connection with device filesystem.
Source code in src/pypalmsens/_instruments/filesystem.py
114 115 116 | |
delete_all_files
Delete all files on the device.
Parameters:
-
(confirmbool, default:False) –If True, clear all files on the device. Default is False. This acts as a sentinel to avoid accidental deletes in interactive REPL or Jupyter environments.
Source code in src/pypalmsens/_instruments/filesystem.py
225 226 227 228 229 230 231 232 233 234 235 236 237 | |
exists
exists(path: str | DevicePath) -> bool
Check whether a path exists on the device.
Parameters:
-
(pathstr | DevicePath) –The file or directory path to check.
Returns:
-
bool–True if the path exists, False otherwise.
Source code in src/pypalmsens/_instruments/filesystem.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
free
free() -> int
Return free space on filesystem.
Returns:
-
int–Free space in bytes (1 kB = 1024 bytes).
Source code in src/pypalmsens/_instruments/filesystem.py
239 240 241 242 243 244 245 246 247 248 | |
iterdir
iterdir(directory: DevicePath | str | None = None) -> Iterator[DevicePath]
Iterate over entries in a device directory.
Note that some devices like EmStat4 return all subdirectories and files at once.
Parameters:
-
(directoryDevicePath | str | None, default:None) –The directory to iterate. Defaults to the root directory.
Yields:
-
paths(Iterator[DevicePath]) –Path objects for each entry in the directory.
Source code in src/pypalmsens/_instruments/filesystem.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
listdir
listdir(directory: DevicePath | str | None = None) -> list[DevicePath]
List all entries in a device directory.
Note that some devices like EmStat4 return all subdirectories and files at once.
Parameters:
-
(directoryDevicePath | str | None, default:None) –The directory to iterate. Defaults to the root directory.
Yields:
-
paths(Iterator[DevicePath]) –Path objects for each entry in the directory.
Source code in src/pypalmsens/_instruments/filesystem.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
load_measurement
load_measurement(path: str | DevicePath) -> Measurement
Load measurement from path on device.
Parameters:
-
(pathstr | DevicePath) –The file path to load.
Returns:
-
Measurement–Measurement data.
Source code in src/pypalmsens/_instruments/filesystem.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |
open
open()
Open connection with device filesystem.
Source code in src/pypalmsens/_instruments/filesystem.py
110 111 112 | |
read_text
read_text(path: DevicePath) -> str
Read the content of a file as text.
Parameters:
-
(pathDevicePath) –The file path.
Returns:
-
str–File contents as a string.
Source code in src/pypalmsens/_instruments/filesystem.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
remove
remove(path: str | DevicePath) -> None
Remove a file from the device.
Parameters:
-
(pathstr | DevicePath) –The file path to remove.
Source code in src/pypalmsens/_instruments/filesystem.py
211 212 213 214 215 216 217 218 219 220 221 222 223 | |
size
size() -> int
Return total size of filesystem.
Returns:
-
int–Total size in bytes.
Source code in src/pypalmsens/_instruments/filesystem.py
250 251 252 253 254 255 256 257 258 259 | |
size_of
size_of(path: str | DevicePath) -> int
Get the size of a file.
Parameters:
-
(pathstr | DevicePath) –The file path.
Returns:
-
int–File size in bytes (1 kB = 1024 bytes).
Source code in src/pypalmsens/_instruments/filesystem.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
timestamp_of
timestamp_of(path: str | DevicePath) -> str
Get the modification timestamp of a file.
Parameters:
-
(pathstr | DevicePath) –The file path.
Returns:
-
str–Timestamp in ISO format.
Source code in src/pypalmsens/_instruments/filesystem.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
walk
walk(directory: DevicePath | str | None = None) -> Iterator[DevicePath]
Generate file names by walking the directory tree starting from a device directory.
Parameters:
-
(directoryDevicePath | str | None, default:None) –The directory to walk through. Defaults to the root directory.
Yields:
-
paths(Iterator[DevicePath]) –Path objects for each entry in the directory.
Source code in src/pypalmsens/_instruments/filesystem.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
pypalmsens.DeviceFileSystemAsync
DeviceFileSystemAsync(instrument_or_manager: Instrument | InstrumentManagerAsync)
Provide a file-system-like interface to a PalmSens device.
Allows browsing, reading, writing, and deleting files on the connected instrument as if they were entries in a local directory tree.
Note that if not used as a context manager, the manager must have an active connection with the device.
Parameters:
-
(instrument_or_managerInstrument | InstrumentManagerAsync) –An instrument instance or an existing
InstrumentManagerAsync. If an instrument is passed, a new manager will be created.
Methods:
-
__truediv__–Join a path component to the root directory.
-
close–Close connection with device filesystem.
-
delete_all_files–Delete all files on the device.
-
exists–Check whether a path exists on the device.
-
free–Return free space on filesystem.
-
iterdir–Iterate over entries in a device directory.
-
listdir–List all entries in a device directory.
-
load_measurement–Load measurement from path on device.
-
open–Open connection with device filesystem.
-
read_text–Read the content of a file as text.
-
remove–Remove a file from the device.
-
size–Return total size of filesystem.
-
size_of–Get the size of a file.
-
timestamp_of–Get the modification timestamp of a file.
-
walk–Generate file names by walking the directory tree starting from a device directory.
Attributes:
-
root(DevicePath) –Return path of root directory.
Source code in src/pypalmsens/_instruments/filesystem_async.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
root
property
root: DevicePath
__truediv__
__truediv__(path_str: str) -> DevicePath
Join a path component to the root directory.
Source code in src/pypalmsens/_instruments/filesystem_async.py
65 66 67 | |
close
async
close()
Close connection with device filesystem.
Source code in src/pypalmsens/_instruments/filesystem_async.py
61 62 63 | |
delete_all_files
async
Delete all files on the device.
Parameters:
-
(confirmbool, default:False) –If True, clear all files on the device. Default is False. This acts as a sentinel to avoid accidental deletes in interactive REPL or Jupyter environments.
Source code in src/pypalmsens/_instruments/filesystem_async.py
185 186 187 188 189 190 191 192 193 194 195 196 197 | |
exists
async
exists(path: str | DevicePath) -> bool
Check whether a path exists on the device.
Parameters:
-
(pathstr | DevicePath) –The file or directory path to check.
Returns:
-
bool–True if the path exists, False otherwise.
Source code in src/pypalmsens/_instruments/filesystem_async.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
free
async
free() -> int
Return free space on filesystem.
Returns:
-
int–Free space in kB (1 kB = 1024 bytes).
Source code in src/pypalmsens/_instruments/filesystem_async.py
199 200 201 202 203 204 205 206 207 208 | |
iterdir
async
iterdir(directory: DevicePath | str | None = None) -> AsyncIterator[DevicePath]
Iterate over entries in a device directory.
Note that some devices like EmStat4 return all subdirectories and files at once.
Parameters:
-
(directoryDevicePath | str | None, default:None) –The directory to iterate. Defaults to the root directory.
Yields:
-
paths(Iterator[DevicePath]) –Path objects for each entry in the directory.
Source code in src/pypalmsens/_instruments/filesystem_async.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
listdir
async
listdir(directory: DevicePath | str | None = None) -> list[DevicePath]
List all entries in a device directory.
Note that some devices like EmStat4 return all subdirectories and files at once.
Parameters:
-
(directoryDevicePath | str | None, default:None) –The directory to iterate. Defaults to the root directory.
Yields:
-
paths(Iterator[DevicePath]) –Path objects for each entry in the directory.
Source code in src/pypalmsens/_instruments/filesystem_async.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
load_measurement
async
load_measurement(path: str | DevicePath) -> Measurement
Load measurement from path on device.
Parameters:
-
(pathstr | DevicePath) –The file path to load.
Returns:
-
Measurement–Measurement data.
Source code in src/pypalmsens/_instruments/filesystem_async.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
open
async
open()
Open connection with device filesystem.
Source code in src/pypalmsens/_instruments/filesystem_async.py
57 58 59 | |
read_text
async
read_text(path: DevicePath) -> str
Read the content of a file as text.
Parameters:
-
(pathDevicePath) –The file path.
Returns:
-
str–File contents as a string.
Source code in src/pypalmsens/_instruments/filesystem_async.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
remove
async
remove(path: str | DevicePath) -> None
Remove a file from the device.
Parameters:
-
(pathstr | DevicePath) –The file path to remove.
Source code in src/pypalmsens/_instruments/filesystem_async.py
171 172 173 174 175 176 177 178 179 180 181 182 183 | |
size
async
size() -> int
Return total size of filesystem.
Returns:
-
int–Total size in kB (1 kB = 1024 bytes).
Source code in src/pypalmsens/_instruments/filesystem_async.py
210 211 212 213 214 215 216 217 218 219 | |
size_of
async
size_of(path: str | DevicePath) -> int
Get the size of a file.
Parameters:
-
(pathstr | DevicePath) –The file path.
Returns:
-
int–File size in bytes.
Source code in src/pypalmsens/_instruments/filesystem_async.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
timestamp_of
async
timestamp_of(path: str | DevicePath) -> str
Get the modification timestamp of a file.
Parameters:
-
(pathstr | DevicePath) –The file path.
Returns:
-
str–Timestamp in ISO format.
Source code in src/pypalmsens/_instruments/filesystem_async.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
walk
async
walk(directory: DevicePath | str | None = None) -> AsyncIterator[DevicePath]
Generate file names by walking the directory tree starting from a device directory.
Parameters:
-
(directoryDevicePath | str | None, default:None) –The directory to walk through. Defaults to the root directory.
Yields:
-
paths(Iterator[DevicePath]) –Path objects for each entry in the directory.
Source code in src/pypalmsens/_instruments/filesystem_async.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |