lakeFS Python SDK Wrapper
Actively maintained. Last release 11 days ago, commits in 18 of the last 26 weeks. A safe choice.
pip install lakefslakeFS High-Level Python SDK
lakeFS High Level SDK for Python, provides developers with the following features:
- Simpler programming interface with less configuration
- Inferring identity from environment
- Better abstractions for common, more complex operations (I/O, transactions, imports)
Requirements
Python 3.10+
Installation & Usage
pip install
pip install lakefs
Import the package
import lakefs
Getting Started
Please follow the installation procedure and afterward refer to the following example snippet for a quick start:
import lakefs
from lakefs.client import Client
# Using default client will attempt to authenticate with lakeFS server using configured credentials
# If environment variables or .lakectl.yaml file exist
repo = lakefs.repository(repository_id="my-repo")
# (The positional argument is simpler!)
repo = lakefs.repository("my-repo")
# Or explicitly initialize and provide a Client object
clt = Client(username="<lakefs_access_key_id>", password="<lakefs_secret_access_key>", host="<lakefs_endpoint>")
repo = lakefs.Repository(repository_id="my-repo", client=clt)
# From this point, proceed using the package according to documentation
main_branch = repo.create(storage_namespace="<storage_namespace>").branch(branch_id="main")
# Prefer to use "repo" rather than pass in the same repository_id each time.
...
Examples
Print sizes of all objects in lakefs://repo/main~2
ref = lakefs.Repository("repo").ref("main~2")
for obj in ref.objects():
print(f"{o.path}: {o.size_bytes}")
Difference between two branches
for i in lakefs.Repository("repo").ref("main").diff("twig"):
print(i)
You can also use the ref expressions here, for instance
.diff("main~2") also works. Ref expressions are the lakeFS analogues of
how Git specifies revisions.
Search a stored object for a string
with lakefs.Repository("repo").ref("main").object("path/to/data").reader(mode="r") as f:
for l in f:
if "quick" in l:
print(l)