An fsspec implementation for lakeFS.
Project description
lakeFS-spec: An fsspec backend for lakeFS
Welcome to lakeFS-spec, a filesystem-spec backend implementation for the lakeFS data lake. Our primary goal is to streamline versioned data operations in lakeFS, enabling seamless integration with popular data science tools such as Pandas, Polars, and DuckDB directly from Python.
Highlights:
- Simple repository operations in lakeFS
- Easy access to underlying storage and versioning operations
- Seamless integration with the fsspec ecosystem
- Directly access lakeFS objects from popular data science libraries (including Pandas, Polars, DuckDB, PyArrow) with minimal code
- Transaction support for reliable data version control
- Smart data transfers through client-side caching (up-/download)
- Auto-discovery configuration
[!NOTE] We are seeking early adopters who would like to actively participate in our feedback process and shape the future of the library. If you are interested in using the library and want to get in touch with us, please reach out via Github Discussions.
Installation
lakeFS-spec is published on PyPI, you can simply install it using your favorite package manager:
$ pip install lakefs-spec
# or
$ poetry add lakefs-spec
Usage
The following usage examples showcase two major ways of using lakeFS-spec: as a low-level filesystem abstraction, and through third-party (data science) libraries.
For a more thorough overview of the features and use cases for lakeFS-spec, see the user guide and tutorials sections in the documentation.
Low-level: As a fsspec filesystem
The following example shows how to upload a file, create a commit, and read back the committed data using the bare lakeFS filesystem implementation.
It assumes you have already created a repository named repo
and have lakectl
credentials set up on your machine in ~/.lakectl.yaml
(see the lakeFS quickstart guide if you are new to lakeFS and need guidance).
from pathlib import Path
from lakefs_spec import LakeFSFileSystem
REPO, BRANCH = "repo", "main"
# Prepare example local data
local_path = Path("demo.txt")
local_path.write_text("Hello, lakeFS!")
# Upload to lakeFS and create a commit
fs = LakeFSFileSystem() # will auto-discover config from ~/.lakectl.yaml
repo_path = f"{REPO}/{BRANCH}/{local_path.name}"
with fs.transaction as tx:
fs.put(str(local_path), repo_path)
tx.commit(REPO, BRANCH, "Add demo data")
# Read back committed file
f = fs.open(repo_path, "rt")
print(f.readline()) # "Hello, lakeFS!"
High-level: Via third-party libraries
A variety of widely-used data science tools are building on fsspec to access remote storage resources and can thus work with lakeFS data lakes directly through lakeFS-spec (see the fsspec docs for details).
The examples assume you have a lakeFS instance with the quickstart
repository containing sample data available.
# Pandas -- see https://pandas.pydata.org/docs/user_guide/io.html#reading-writing-remote-files
import pandas as pd
data = pd.read_parquet("lakefs://quickstart/main/lakes.parquet")
print(data.head())
# Polars -- see https://pola-rs.github.io/polars/user-guide/io/cloud-storage/
import polars as pl
data = pl.read_parquet("lakefs://quickstart/main/lakes.parquet")
print(data.head())
# DuckDB -- see https://duckdb.org/docs/guides/python/filesystems.html
import duckdb
import fsspec
duckdb.register_filesystem(fsspec.filesystem("lakefs"))
res = duckdb.read_parquet("lakefs://quickstart/main/lakes.parquet")
res.show()
Contributing
We encourage and welcome contributions from the community to enhance the project. Please check discussions or raise an issue on GitHub for any problems you encounter with the library.
For information on the general development workflow, see the contribution guide.
License
The lakeFS-spec library is distributed under the Apache-2 license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for lakefs_spec-0.6.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f487790b7692abe6e5daaf6f3e31572c944835464a0f4aea8541fa79c382431 |
|
MD5 | d1134c85b44043f60848e109fccdb7db |
|
BLAKE2b-256 | 804d6a6f09804ce7f74f2636c131e7c2b469bfac068513c8e80d75fa191806b8 |