Skip to main content

oxen.oxen_fs

OxenFS Objects

OxenFS is a filesystem interface for Oxen repositories that implements the fsspec protocol. This allows you to interact with Oxen repositories using familiar filesystem operations and integrate with other compatible libraries like Pandas.

Basic Usage

Creating a Filesystem Instance

Reading Files

Writing Files

You must have write access to the repository to write files. See: https://docs.oxen.ai/getting-started/python#private-repositories OxenFS will automatically commit the file to the repository when the context is exited (or the file is closed some other way). New directories are automatically created as needed.

Writing file objects

If you’re integrating Oxen in a situation where you already have a file object, you can save it to your repo by using shutil.copyfileobj like this:

Integration with Third Party Libraries (Pandas, etc.)

OxenFS works seamlessly with Pandas and other fsspec-compatible libraries using the URL format: oxen://namespace:repo@revision/path/to/file

Reading Data

These will work with Pandas {to,from}_{csv,parquet,json,etc.} functions.

Writing Data

Notes

  • Only binary read (“rb”) and write (“wb”) modes are currently supported
    • But writing will automatically encode strings to bytes
  • Does not yet support streaming files. All operations use temporary local files.

__init__

Initialize the OxenFS instance. Arguments:
  • namespace - str The namespace of the repository.
  • repo - str The name of the repository.
  • host - str The host to connect to. Defaults to ‘hub.oxen.ai’
  • revision - str The branch name or commit id to checkout. Defaults to ‘main’
  • scheme - str The scheme to use for the remote url. Default: ‘https’

ls

List the contents of a directory. Arguments:
  • path - str The path to list the contents of.
  • detail - bool If True, return a list of dictionaries with detailed metadata. Otherwise, return a list of strings with the filenames.

OxenFSFileWriter Objects

A file writer for the OxenFS backend. This is normally called through OxenFS.open() or fsspec.open().

write

Write string or binary data to the file.

flush

Flush the file to disk.

tell

Return the current position of the file.

seek

Seek to a specific position in the file.

commit

Commit the file to the remote repo.

close

Close the file writer. This will commit the file to the remote repo.