lakeFS Python SDK

0.16.0 · active · verified Sat Apr 11

The lakeFS Python SDK provides a high-level, ergonomic interface for interacting with a lakeFS data lake. It simplifies operations like creating repositories, managing branches, committing data, and performing data versioning tasks. The current library version is 0.16.0, with releases occurring periodically to support new lakeFS server features and improve usability, typically decoupled from the rapid server release cycle.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the lakeFS client and list existing repositories. The client automatically attempts to load configuration from environment variables (LAKECTL_SERVER_URL, LAKECTL_ACCESS_KEY_ID, LAKECTL_SECRET_ACCESS_KEY) or a `lakectl` configuration file. Ensure your lakeFS server is running and credentials are set up.

import os
from lakefs.client import LakeFSClient

# It's recommended to set these environment variables:
# LAKECTL_SERVER_URL (e.g., "http://localhost:8000")
# LAKECTL_ACCESS_KEY_ID
# LAKECTL_SECRET_ACCESS_KEY

# Initialize the client. It will attempt to load credentials
# from environment variables or a lakectl config file by default.
# You can also pass them explicitly:
# client = LakeFSClient(
#     uri="http://localhost:8000",
#     access_key_id="YOUR_ACCESS_KEY_ID",
#     secret_access_key="YOUR_SECRET_ACCESS_KEY"
# )

try:
    client = LakeFSClient(
        uri=os.environ.get('LAKECTL_SERVER_URL', 'http://localhost:8000'),
        access_key_id=os.environ.get('LAKECTL_ACCESS_KEY_ID', ''),
        secret_access_key=os.environ.get('LAKECTL_SECRET_ACCESS_KEY', '')
    )
    
    # Example: List repositories
    print("Attempting to connect to lakeFS and list repositories...")
    repos_iterator = client.repositories.list()
    
    repos = list(repos_iterator) # Consume the iterator

    if repos:
        print("Found repositories:")
        for repo in repos:
            print(f"- {repo.id}")
    else:
        print("No repositories found. Create one first (e.g., via lakectl CLI or UI).")

except Exception as e:
    print(f"Error connecting to lakeFS or listing repositories: {e}")
    print("Please ensure lakeFS server is running and credentials are configured correctly (environment variables or lakectl config file).")

view raw JSON →