pyuv.fs — Asynchronous filesystem operations

Note

All functions in the fs module except for the FSEvent and FSPoll classes support both synchronous and asynchronous modes. If you want to run it synchronous don’t pass any callable as the callback argument, else it will run asynchronously. If the async form is used, then a FSRequest is returned when calling the functions, which has a cancel() method that can be called in order to cancel the request, in case it hasn’t run yet.

Note

All functions that take a file descriptor argument must get the file descriptor resulting of a pyuv.fs.open call on Windows, else the operation will fail. This limitation doesn’t apply to Unix systems.

pyuv.fs.stat(loop, path[, callback])
Parameters:
  • path (string) – File to stat.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

stat syscall.

Callback signature: callback(loop, path, stat_result, errorno)

pyuv.fs.lstat(path, loop[, callback])

Same as pyuv.fs.stat() but it also follows symlinks.

pyuv.fs.fstat(fd, loop[, callback])

Same as pyuv.fs.stat() but using a file-descriptor instead of the path.

Parameters:
  • path (string) – File to unlink.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Remove the specified file.

Callback signature: callback(loop, path, errorno)

pyuv.fs.mkdir(loop, path[, callback])
Parameters:
  • path (string) – Directory to create.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Create the specified directory.

Callback signature: callback(loop, path, errorno)

pyuv.fs.rmdir(loop, path[, callback])
Parameters:
  • path (string) – Directory to remove.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Remove the specified directory.

Callback signature: callback(loop, path, errorno)

pyuv.fs.rename(loop, path, new_path[, callback])
Parameters:
  • path (string) – Original file.
  • new_path (string) – New name for the file.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Rename file.

Callback signature: callback(loop, path, errorno)

pyuv.fs.chmod(loop, path, mode[, callback])
Parameters:
  • path (string) – File which permissions will be changed.
  • mode (int) – File permissions (ex. 0755)
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Remove the specified directory.

Callback signature: callback(loop, path, errorno)

pyuv.fs.fchmod(loop, fd, mode[, callback])

Same as pyuv.fs.chmod() but using a file-descriptor instead of the path.

Parameters:
  • path (string) – Original file.
  • new_path (string) – Name for the hard-link.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Create a hard-link.

Callback signature: callback(loop, path, errorno)

Parameters:
  • path (string) – Original file.
  • new_path (string) – Name for the symlink.
  • loop – loop object where this function runs.
  • flags (int) – flags to be used on Windows platform. If UV_FS_SYMLINK_DIR is specified the symlink will be created to a directory. If UV_FS_SYMLINK_JUNCTION a junction point will be created instead of a symlink.
  • callback (callable) – Function that will be called with the result of the function.

Create a symlink.

Callback signature: callback(loop, path, errorno)

Parameters:
  • path (string) – Link file to process.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Read link file and return the original file path.

Callback signature: callback(loop, path, errorno)

pyuv.fs.chown(loop, path, uid, gid[, callback])
Parameters:
  • path (string) – File which persmissions will be changed.
  • uid (int) – User ID.
  • gid (int) – Group ID.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Changes ownership of a file.

Callback signature: callback(loop, path, errorno)

pyuv.fs.fchown(loop, fd, mode[, callback])

Same as pyuv.fs.chown() but using a file-descriptor instead of the path.

pyuv.fs.open(loop, path, flags, mode[, callback])
Parameters:
  • path (string) – File to open.
  • flags (int) – Flags for opening the file. Check os.O_ constants.
  • mode (int) – Mode for opening the file. Check stat.S_ constants.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Open file.

Callback signature: callback(loop, path, fd, errorno)

pyuv.fs.close(loop, fd[, callback])
Parameters:
  • fd (int) – File-descriptor to close.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Close file.

Callback signature: callback(loop, path, errorno)

pyuv.fs.read(loop, fd, length, offset[, callback])
Parameters:
  • fd (int) – File-descriptor to read from.
  • length (int) – Amount of bytes to be read.
  • offset (int) – File offset.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Read from file.

Callback signature: callback(loop, path, read_data, errorno)

pyuv.fs.write(loop, fd, write_data, offset[, callback])
Parameters:
  • fd (int) – File-descriptor to read from.
  • write_data (string) – Data to be written.
  • offset (int) – File offset.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Write to file.

Callback signature: callback(loop, path, bytes_written, errorno)

pyuv.fs.fsync(loop, fd[, callback])
Parameters:
  • fd (int) – File-descriptor to sync.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Sync all changes made to file.

Callback signature: callback(loop, path, errorno)

pyuv.fs.fdatasync(loop, fd[, callback])
Parameters:
  • fd (int) – File-descriptor to sync.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Sync data changes made to file.

Callback signature: callback(loop, path, errorno)

pyuv.fs.ftruncate(loop, fd, offset[, callback])
Parameters:
  • fd (int) – File-descriptor to truncate.
  • offset (int) – File offset.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Truncate the contents of a file to the specified offset.

Callback signature: callback(loop, path, errorno)

pyuv.fs.readdir(loop, path, flags[, callback])
Parameters:
  • path (string) – Directory to list.
  • flags (int) – Unused.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

List files from a directory.

Callback signature: callback(loop, path, files, errorno)

pyuv.fs.sendfile(loop, out_fd, in_fd, in_offset, length[, callback])
Parameters:
  • in_fd (int) – File-descriptor to read from.
  • in_fd – File-descriptor to write to.
  • length (int) – Amount of bytes to be read.
  • offset (int) – File offset.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Send a regular file to a stream socket.

Callback signature: callback(loop, path, bytes_written, errorno)

pyuv.fs.utime(loop, path, atime, mtime[, callback])
Parameters:
  • path (string) – Directory to list.
  • atime (double) – New accessed time.
  • mtime (double) – New modified time.
  • loop – loop object where this function runs.
  • callback (callable) – Function that will be called with the result of the function.

Update file times.

Callback signature: callback(loop, path, files, errorno)

pyuv.fs.futime(loop, fd, atime, mtime[, callback])

Same as pyuv.fs.utime() but using a file-descriptor instead of the path.

class pyuv.fs.FSEvent(loop, path, callback, flags)
Parameters:
  • loop (Loop) – loop object where this handle runs (accessible through FSEvent.loop).
  • path (string) – Path to monitor for events.
  • callback (callable) – Function that will be called when an event occurs in the given path.
  • flags (int) – Flags which control what events are watched for. Not used at the moment.

FSEvent handles monitor a given path for changes.

Callback signature: callback(fsevent_handle, filename, events, error).
close([callback])
Parameters:callback (callable) – Function that will be called after the FSEvent handle is closed.

Close the FSEvent handle. After a handle has been closed no other operations can be performed on it.

Callback signature: callback(fsevent_handle).

loop

Read only

Loop object where this handle runs.

filename

Read only

Filename being monitored.

active

Read only

Indicates if this handle is active.

closed

Read only

Indicates if this handle is closing or already closed.

class pyuv.fs.FSPoll(loop)
Parameters:loop (Loop) – loop object where this handle runs (accessible through FSPoll.loop).

FSPoll handles monitor a given path for changes by using stat syscalls.

start(path, callback, interval)
Parameters:
  • path (string) – Path to monitor for changes.
  • callback (callable) – Function that will be called when the given path changes any of its attributes.
  • interval (float) – How often to poll for events (in seconds).

Start the FSPoll handle.

Callback signature: callback(fspoll_handle, prev_stat, curr_stat, error).

close([callback])
Parameters:callback (callable) – Function that will be called after the FSPoll handle is closed.

Close the FSPoll handle. After a handle has been closed no other operations can be performed on it.

Callback signature: callback(fspoll_handle).

loop

Read only

Loop object where this handle runs.

active

Read only

Indicates if this handle is active.

closed

Read only

Indicates if this handle is closing or already closed.

Module constants

pyuv.fs.UV_RENAME
pyuv.fs.UV_CHANGE
pyuv.fs.UV_FS_EVENT_WATCH_ENTRY
pyuv.fs.UV_FS_EVENT_STAT

Previous topic

puyv.dns — Asynchronous DNS resolver using c-ares

Next topic

pyuv.error — Exception definitions

This Page