lakeFS SDK
The `lakefs-sdk` is the low-level Python client for interacting with the lakeFS API. It provides direct access based on the OpenAPI specification, offering full control over API interactions. It is distinct from the higher-level `lakefs` SDK, which provides a more Pythonic interface for common operations. The library is actively maintained with frequent releases, currently at version 1.80.0.
Warnings
- breaking The `lakefs-client` package is deprecated as of lakeFS 1.0 (last release v1.44.0) and is no longer supported for new updates or features. Users should migrate to `lakefs-sdk` (for low-level API access) or the higher-level `lakefs` package.
- gotcha There are two main Python SDKs for lakeFS: `lakefs-sdk` (low-level, auto-generated, direct API calls) and `lakefs` (high-level, Pythonic interface for common operations like branches, commits, objects, transactions). Choosing the wrong SDK can lead to more complex code than necessary for common tasks.
- breaking Migrating to lakeFS 1.0 and the `lakefs-sdk` from older `lakefs-client` versions involved API changes, such as renaming the `model` module to `models` and `apis` to `api`. Also, fetching results from response objects changed from dictionary-like access (`get_property`) to direct attribute access (`prop_name`).
- gotcha The `lakefs-sdk` requires explicit configuration of host and credentials. Unlike the higher-level `lakefs` SDK, it does not automatically infer identity from environment variables (`LAKEFS_ACCESS_KEY_ID`, `LAKEFS_SECRET_ACCESS_KEY`, `LAKEFS_SERVER_ENDPOINT_URL`) or a local `.lakectl.yaml` file without explicit handling.
- deprecated OpenID Connect (OIDC) support for authentication via older configuration methods is deprecated. For single sign-on (SSO) or short-lived token (STS-like) authentication, users should consider lakeFS Cloud or Enterprise features.
Install
-
pip install lakefs-sdk
Imports
- Configuration
from lakefs_sdk import Configuration
- ApiClient
from lakefs_sdk import ApiClient
- RepositoriesApi
from lakefs_sdk.apis import RepositoriesApi
- ApiException
from lakefs_sdk.rest import ApiException
- lakefs_client
from lakefs_sdk import Configuration, ApiClient
Quickstart
import os
import lakefs_sdk
from lakefs_sdk.apis import RepositoriesApi
from lakefs_sdk.rest import ApiException
# Configure API client with credentials from environment variables
configuration = lakefs_sdk.Configuration(
host=os.environ.get('LAKEFS_SERVER_ENDPOINT_URL', 'https://example.lakefs.io/api/v1'),
username=os.environ.get('LAKEFS_ACCESS_KEY_ID', ''),
password=os.environ.get('LAKEFS_SECRET_ACCESS_KEY', '')
)
# Create an API client instance
with lakefs_sdk.ApiClient(configuration) as api_client:
# Create an instance of the Repositories API
repositories_api = RepositoriesApi(api_client)
try:
# List repositories
repos = repositories_api.list_repositories()
print("Successfully connected to lakeFS!")
print("Repositories:")
for repo in repos.results:
print(f"- {repo.id}")
except ApiException as e:
print(f"Error connecting to lakeFS or listing repositories: {e}")
print("Ensure LAKEFS_SERVER_ENDPOINT_URL, LAKEFS_ACCESS_KEY_ID, and LAKEFS_SECRET_ACCESS_KEY are set.")