https://lakefs.io/ logo
Title
a

Aapta Bhatt

05/03/2023, 6:55 PM
Hi Team, Is there anyway with lakefs sdk to find out if a repository and branch exists or not ?
a

Ariel Shaqed (Scolnicov)

05/03/2023, 7:05 PM
Hi @Aapta Bhatt, That's a great question! The lakeFS API is pretty standard REST. In this case, rather than ask whether the repo exists I'd just GET the repository. If it doesn't exist I get a 404 response. If it exists, I'll get a response that I don't care about. Similarly GET the branch to check whether it exists. I don't think we have an actual HEAD operation on these: neither is a large object, it would save nothing to run a less informative check.
a

Aapta Bhatt

05/03/2023, 7:22 PM
Can you please give me example ?
i

Iddo Avneri

05/03/2023, 7:35 PM
Hi @Aapta Bhatt - First, FWIW, you can list repositories (or branches)
client.repositories.list_repositories()
Or:
client.branches.list_branches('learn-lakefs-repo01')
And, if you try and access a repo that doesn’t exist you will get the 404 response:
client.branches.list_branches('cant-find-me')
NotFoundException: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({'Date': 'Wed, 03 May 2023 19:37:25 GMT', 'Content-Type': 'application/json', 'Content-Length': '35', 'Connection': 'keep-alive', 'X-Content-Type-Options': 'nosniff', 'X-Request-Id': '74ac0755-5959-4fb9-80eb-012030c92bda'})
HTTP response body: {"message":"repository not found"}
a

Ariel Shaqed (Scolnicov)

05/03/2023, 7:44 PM
@Iddo Avneri’s method works great. Perhaps more
client.repositories.get_repository('no_such_repo')
or
client.branches.get_branch('my-repo', 'no-such-branch-in-my-repo')
Both should return the same 404.
🙏 1
🙏🏽 1