Skip to content

Commit

Permalink
Python Wrapper: Implement repository list (#7119)
Browse files Browse the repository at this point in the history
  • Loading branch information
N-o-Z authored Dec 6, 2023
1 parent e6c502a commit 7a59eaa
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion clients/python-wrapper/lakefs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Allow importing of models from package root
"""

from lakefs.repository import Repository
from lakefs.repository import Repository, repositories
from lakefs.reference import Reference
from lakefs.models import (
Commit,
Expand Down
24 changes: 23 additions & 1 deletion clients/python-wrapper/lakefs/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from lakefs.tag import Tag
from lakefs.branch import Branch
from lakefs.client import Client, DEFAULT_CLIENT
from lakefs.exceptions import api_exception_handler, ConflictException, LakeFSException
from lakefs.exceptions import api_exception_handler, ConflictException, LakeFSException, NoAuthenticationFound
from lakefs.reference import Reference, generate_listing


Expand Down Expand Up @@ -161,3 +161,25 @@ def properties(self) -> RepositoryProperties:
return self._properties

return self._properties


def repositories(client: Client = DEFAULT_CLIENT,
prefix: Optional[str] = None,
after: Optional[str] = None,
**kwargs) -> Generator[Repository]:
"""
Creates a repositories object generator listing lakeFS repositories
:param client: The lakeFS client to use, if None, tries to use the default client
:param prefix: Return items prefixed with this value
:param after: Return items after this value
:return: A generator listing lakeFS repositories
"""
if client is None:
raise NoAuthenticationFound("Explicitly provide a client or invoke client module's init method")

for res in generate_listing(client.sdk_client.repositories_api.list_repositories,
prefix=prefix,
after=after,
**kwargs):
yield Repository(res.id, client)
13 changes: 13 additions & 0 deletions clients/python-wrapper/tests/integration/test_repository.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import pytest
import uuid
import lakefs

from tests.integration.conftest import _setup_repo, get_storage_namespace

Expand Down Expand Up @@ -35,3 +37,14 @@ def test_repository_listings(setup_repo_with_branches_and_tags, attr):
assert len(res) == 10
for i, b in enumerate(res):
assert b.id == f"{attr}01-{i + after + 1:02d}"


def test_repositories(storage_namespace):
repo_base_name = f"test-repo{uuid.uuid1()}-"
for i in range(10):
lakefs.repository(f"{repo_base_name}{i}").create(storage_namespace=f"{storage_namespace}-{i}")

repos = list(lakefs.repositories(prefix=repo_base_name))
assert len(repos) == 10
for i, repo in enumerate(repos):
assert repo.properties.id == f"{repo_base_name}{i}"

0 comments on commit 7a59eaa

Please sign in to comment.