diff --git a/00_notebooks/rbac-demo.ipynb b/00_notebooks/rbac-demo.ipynb index 022511c47..847be7dcd 100644 --- a/00_notebooks/rbac-demo.ipynb +++ b/00_notebooks/rbac-demo.ipynb @@ -39,17 +39,25 @@ "![RBAC](./images/RBAC.png)" ] }, + { + "cell_type": "markdown", + "id": "2d06bdc4-9a08-48b8-bc8f-c1d7a23fcc97", + "metadata": {}, + "source": [ + "## Config" + ] + }, { "cell_type": "markdown", "id": "387f4469-9708-435d-bec9-c943fd87a0bf", "metadata": {}, "source": [ - "## Change your lakeFS credentials" + "### Change your lakeFS credentials" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "id": "dfa46799-5f86-4104-9447-d91328edbff4", "metadata": {}, "outputs": [], @@ -61,39 +69,49 @@ }, { "cell_type": "markdown", - "id": "fc6d8ce9-1147-4d4c-9882-9718fde1ddde", + "id": "13d1c562-9899-4343-b887-c5c018ea79b0", "metadata": {}, "source": [ - "## You can change lakeFS repo name (it can be an existing repo or provide another repo name)" + "### Storage Information\n", + "##### Change the Storage Namespace to a location in the bucket you’ve configured. The storage namespace is a location in the underlying storage where data for this repository will be stored." ] }, { "cell_type": "code", - "execution_count": 14, - "id": "c6e3c546-98b9-4e4e-a9c0-c6737758ce20", + "execution_count": null, + "id": "25b151c2-743d-43e1-9f2f-25482967c207", "metadata": {}, "outputs": [], "source": [ - "repo = \"rbac-repo\"" + "storageNamespace = 's3:///' # e.g. \"s3://username-lakefs-cloud/\"" ] }, { "cell_type": "markdown", - "id": "13d1c562-9899-4343-b887-c5c018ea79b0", + "id": "debe8733-d1f8-4b54-961b-33fc40535fe1", "metadata": {}, "source": [ - "## Storage Information\n", - "#### Change the Storage Namespace to a location in the bucket you’ve configured. The storage namespace is a location in the underlying storage where data for this repository will be stored." + "## Setup\n", + "\n", + "**(you shouldn't need to change anything in this section, just run it)**" + ] + }, + { + "cell_type": "markdown", + "id": "fc6d8ce9-1147-4d4c-9882-9718fde1ddde", + "metadata": {}, + "source": [ + "## You can change lakeFS repo name (it can be an existing repo or provide another repo name)" ] }, { "cell_type": "code", - "execution_count": 15, - "id": "25b151c2-743d-43e1-9f2f-25482967c207", + "execution_count": null, + "id": "c6e3c546-98b9-4e4e-a9c0-c6737758ce20", "metadata": {}, "outputs": [], "source": [ - "storageNamespace = 's3:///' # e.g. \"s3://username-lakefs-cloud/\"" + "repo_name = \"rbac-repo\"" ] }, { @@ -106,7 +124,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, "id": "3b839850-5954-4631-8e7e-d0dee6d17dde", "metadata": {}, "outputs": [], @@ -116,6 +134,32 @@ "fileName = \"lakefs_test.csv\"" ] }, + { + "cell_type": "markdown", + "id": "b7ae3a20-86f3-411f-83b5-b77a7ad3293f", + "metadata": {}, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63c6251a-9545-4292-8663-4785edd29b4b", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "%xmode Minimal\n", + "import lakefs\n", + "from lakefs.client import Client\n", + "import lakefs_sdk\n", + "from lakefs_sdk.client import LakeFSClient\n", + "from lakefs_sdk import models\n", + "from assets.lakefs_demo import print_commit" + ] + }, { "cell_type": "markdown", "id": "a7ede096-1b84-4b59-bdd1-2608ced6be51", @@ -126,33 +170,46 @@ }, { "cell_type": "code", - "execution_count": 17, - "id": "468e98e4-7e06-4373-b36b-f1763cc7755d", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Exception reporting mode: Minimal\n" - ] - } - ], + "execution_count": null, + "id": "08f45f04-5425-4224-8da2-88c5e506a6ba", + "metadata": { + "tags": [] + }, + "outputs": [], "source": [ - "%xmode Minimal\n", "if not 'superUserClient' in locals():\n", - " import lakefs_client\n", - " from lakefs_client import models\n", - " from lakefs_client.client import LakeFSClient\n", - "\n", - " # lakeFS credentials and endpoint\n", - " configuration = lakefs_client.Configuration()\n", - " configuration.username = lakefsAccessKey\n", - " configuration.password = lakefsSecretKey\n", - " configuration.host = lakefsEndPoint\n", - "\n", - " superUserClient = LakeFSClient(configuration)\n", - " print(\"Created lakeFS client.\")" + " configuration = lakefs_sdk.Configuration(\n", + " host=lakefsEndPoint,\n", + " username=lakefsAccessKey,\n", + " password=lakefsSecretKey,\n", + " )\n", + " superUserClient = LakeFSClient(configuration)" + ] + }, + { + "cell_type": "markdown", + "id": "522255a6-b7f0-47f6-ac70-106fd4ee2a65", + "metadata": {}, + "source": [ + "### Verify lakeFS credentials by getting lakeFS version" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3c92d094-5a07-42d7-9167-7a14c8bfff04", + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "print(\"Verifying lakeFS credentials…\")\n", + "try:\n", + " v=superUserClient.internal_api.get_lake_fs_version().version\n", + "except:\n", + " print(\"🛑 failed to get lakeFS version\")\n", + "else:\n", + " print(f\"…✅lakeFS credentials verified\\n\\nℹ️lakeFS version {v}\")" ] }, { @@ -165,23 +222,14 @@ }, { "cell_type": "code", - "execution_count": 18, - "id": "bfa79754-8ce8-489d-9750-a13f79ca1969", - "metadata": {}, - "outputs": [ - { - "ename": "ProtocolError", - "evalue": "('Connection aborted.', InvalidURL(\"URL can't contain control characters. '' (found at least ' ')\"))", - "output_type": "error", - "traceback": [ - "\u001b[0;31mInvalidURL\u001b[0m\u001b[0;31m:\u001b[0m URL can't contain control characters. '' (found at least ' ')\n", - "\nDuring handling of the above exception, another exception occurred:\n", - "\u001b[0;31mProtocolError\u001b[0m\u001b[0;31m:\u001b[0m ('Connection aborted.', InvalidURL(\"URL can't contain control characters. '' (found at least ' ')\"))\n" - ] - } - ], + "execution_count": null, + "id": "9d874bce-215a-4dc9-828b-c14a55871ff5", + "metadata": { + "tags": [] + }, + "outputs": [], "source": [ - "superUserClient.auth.create_user(\n", + "superUserClient.auth_api.create_user(\n", " user_creation=models.UserCreation(\n", " id='admin1'))" ] @@ -197,12 +245,27 @@ { "cell_type": "code", "execution_count": null, - "id": "a5496d49-1bb4-4ad2-9390-8b9bd51a8436", - "metadata": {}, + "id": "29d0afcd-3426-4f4d-a064-ebf6ed9e23f3", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "superUserClient.auth.add_group_membership(\n", - " group_id='Admins',\n", + "groupName='Admins'\n", + "\n", + "has_more = True\n", + "next_offset = \"\"\n", + "while has_more:\n", + " groups = superUserClient.auth_api.list_groups(after=next_offset)\n", + " for r in groups.results:\n", + " if r.name == groupName:\n", + " groupId = r.id\n", + " break\n", + " has_more = groups.pagination.has_more\n", + " next_offset = groups.pagination.next_offset\n", + " \n", + "superUserClient.auth_api.add_group_membership(\n", + " group_id=groupId,\n", " user_id='admin1')" ] }, @@ -221,7 +284,7 @@ "metadata": {}, "outputs": [], "source": [ - "credentials = superUserClient.auth.create_credentials(user_id='admin1')\n", + "credentials = superUserClient.auth_api.create_credentials(user_id='admin1')\n", "print(credentials)\n", "admin1AccessKey = credentials.access_key_id\n", "admin1SecretKey = credentials.secret_access_key" @@ -238,17 +301,25 @@ { "cell_type": "code", "execution_count": null, - "id": "b0744268-7ad2-40b2-8eae-094c929e6d41", - "metadata": {}, + "id": "93f7b8c5-92a4-4634-9d05-ae7d2186e069", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "# lakeFS credentials and endpoint\n", - "configuration = lakefs_client.Configuration()\n", - "configuration.username = admin1AccessKey\n", - "configuration.password = admin1SecretKey\n", - "configuration.host = lakefsEndPoint\n", - "\n", + "configuration = lakefs_sdk.Configuration(\n", + " host=lakefsEndPoint,\n", + " username=admin1AccessKey,\n", + " password=admin1SecretKey,\n", + ")\n", "admin1Client = LakeFSClient(configuration)\n", + "\n", + "admin1LakefsClient = Client(\n", + " host=lakefsEndPoint,\n", + " username=admin1AccessKey,\n", + " password=admin1SecretKey,\n", + ")\n", + " \n", "print(\"Created lakeFS client for admin1.\")" ] }, @@ -267,7 +338,7 @@ "metadata": {}, "outputs": [], "source": [ - "admin1Client.auth.get_current_user()" + "admin1Client.auth_api.get_current_user()" ] }, { @@ -286,7 +357,7 @@ "metadata": {}, "outputs": [], "source": [ - "admin1Client.auth.create_user(\n", + "admin1Client.auth_api.create_user(\n", " user_creation=models.UserCreation(\n", " id='developer1'))" ] @@ -302,12 +373,27 @@ { "cell_type": "code", "execution_count": null, - "id": "1d7e5ae3-8e2c-49c5-83ea-49ef7310a4d8", - "metadata": {}, + "id": "cf9691fa-9f96-4c39-87cd-8f1952a4e136", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "admin1Client.auth.add_group_membership(\n", - " group_id='Developers',\n", + "groupNameDevelopers='Developers'\n", + "\n", + "has_more = True\n", + "next_offset = \"\"\n", + "while has_more:\n", + " groups = superUserClient.auth_api.list_groups(after=next_offset)\n", + " for r in groups.results:\n", + " if r.name == groupNameDevelopers:\n", + " groupIdDevelopers = r.id\n", + " break\n", + " has_more = groups.pagination.has_more\n", + " next_offset = groups.pagination.next_offset\n", + " \n", + "admin1Client.auth_api.add_group_membership(\n", + " group_id=groupIdDevelopers,\n", " user_id='developer1')" ] }, @@ -326,7 +412,7 @@ "metadata": {}, "outputs": [], "source": [ - "credentials = admin1Client.auth.create_credentials(user_id='developer1')\n", + "credentials = admin1Client.auth_api.create_credentials(user_id='developer1')\n", "print(credentials)\n", "developer1AccessKey = credentials.access_key_id\n", "developer1SecretKey = credentials.secret_access_key" @@ -343,17 +429,25 @@ { "cell_type": "code", "execution_count": null, - "id": "d8372c6c-2c3a-4d91-b4d2-af00656476c2", - "metadata": {}, + "id": "85c62ee7-4fdf-4203-8446-108ec4c251cb", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "# lakeFS credentials and endpoint\n", - "configuration = lakefs_client.Configuration()\n", - "configuration.username = developer1AccessKey\n", - "configuration.password = developer1SecretKey\n", - "configuration.host = lakefsEndPoint\n", - "\n", + "configuration = lakefs_sdk.Configuration(\n", + " host=lakefsEndPoint,\n", + " username=developer1AccessKey,\n", + " password=developer1SecretKey,\n", + ")\n", "developer1Client = LakeFSClient(configuration)\n", + "\n", + "developer1LakeFSClient = Client(\n", + " host=lakefsEndPoint,\n", + " username=developer1AccessKey,\n", + " password=developer1SecretKey,\n", + ")\n", + " \n", "print(\"Created lakeFS client for developer1.\")" ] }, @@ -372,7 +466,7 @@ "metadata": {}, "outputs": [], "source": [ - "developer1Client.auth.get_current_user()" + "developer1Client.auth_api.get_current_user()" ] }, { @@ -390,7 +484,7 @@ "metadata": {}, "outputs": [], "source": [ - "admin1Client.auth.create_group(\n", + "DataScientistsGroup = admin1Client.auth_api.create_group(\n", " group_creation=models.GroupCreation(\n", " id='DataScientists'))" ] @@ -406,12 +500,14 @@ { "cell_type": "code", "execution_count": null, - "id": "0ac35011-8db9-4976-9a41-dfb1313ccd0b", - "metadata": {}, + "id": "4e538c54-76ab-490b-8383-fa4c65ae0593", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "admin1Client.auth.attach_policy_to_group(\n", - " group_id='DataScientists',\n", + "admin1Client.auth_api.attach_policy_to_group(\n", + " group_id=DataScientistsGroup.id,\n", " policy_id='AuthManageOwnCredentials')" ] }, @@ -426,12 +522,12 @@ { "cell_type": "code", "execution_count": null, - "id": "27f6c806-db6a-45ad-ad81-dc749949eabc", + "id": "822d7660-b4a9-489c-9812-6efb2bf9642a", "metadata": {}, "outputs": [], "source": [ - "admin1Client.auth.attach_policy_to_group(\n", - " group_id='DataScientists',\n", + "admin1Client.auth_api.attach_policy_to_group(\n", + " group_id=DataScientistsGroup.id,\n", " policy_id='FSReadWriteAll')" ] }, @@ -446,12 +542,12 @@ { "cell_type": "code", "execution_count": null, - "id": "e0e154c0-5529-47ad-899f-d7fa01e7cef9", + "id": "e53e3325-e641-4fa4-af61-e275898ba885", "metadata": {}, "outputs": [], "source": [ - "admin1Client.auth.attach_policy_to_group(\n", - " group_id='DataScientists',\n", + "admin1Client.auth_api.attach_policy_to_group(\n", + " group_id=DataScientistsGroup.id,\n", " policy_id='RepoManagementReadAll')" ] }, @@ -470,7 +566,7 @@ "metadata": {}, "outputs": [], "source": [ - "admin1Client.auth.create_user(\n", + "admin1Client.auth_api.create_user(\n", " user_creation=models.UserCreation(\n", " id='data_scientist1'))" ] @@ -486,12 +582,12 @@ { "cell_type": "code", "execution_count": null, - "id": "9ed40f7a-1aff-42fa-b4b9-3fbb20938905", + "id": "23771e33-75f3-41a1-9abc-8c37d1aa09eb", "metadata": {}, "outputs": [], "source": [ - "admin1Client.auth.add_group_membership(\n", - " group_id='DataScientists',\n", + "admin1Client.auth_api.add_group_membership(\n", + " group_id=DataScientistsGroup.id,\n", " user_id='data_scientist1')" ] }, @@ -510,7 +606,7 @@ "metadata": {}, "outputs": [], "source": [ - "credentials = admin1Client.auth.create_credentials(user_id='data_scientist1')\n", + "credentials = admin1Client.auth_api.create_credentials(user_id='data_scientist1')\n", "print(credentials)\n", "data_scientist1AccessKey = credentials.access_key_id\n", "data_scientist1SecretKey = credentials.secret_access_key" @@ -527,17 +623,25 @@ { "cell_type": "code", "execution_count": null, - "id": "9dd2ec4d-6401-44ce-af2f-635717d35c05", - "metadata": {}, + "id": "4ebd9e01-311f-49f8-bdbf-a1949a5bec07", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "# lakeFS credentials and endpoint\n", - "configuration = lakefs_client.Configuration()\n", - "configuration.username = data_scientist1AccessKey\n", - "configuration.password = data_scientist1SecretKey\n", - "configuration.host = lakefsEndPoint\n", - "\n", + "configuration = lakefs_sdk.Configuration(\n", + " host=lakefsEndPoint,\n", + " username=data_scientist1AccessKey,\n", + " password=data_scientist1SecretKey,\n", + ")\n", "data_scientist1Client = LakeFSClient(configuration)\n", + "\n", + "data_scientist1LakeFSClient = Client(\n", + " host=lakefsEndPoint,\n", + " username=data_scientist1AccessKey,\n", + " password=data_scientist1SecretKey,\n", + ")\n", + " \n", "print(\"Created lakeFS client for data_scientist1.\")" ] }, @@ -556,7 +660,7 @@ "metadata": {}, "outputs": [], "source": [ - "data_scientist1Client.auth.get_current_user()" + "data_scientist1Client.auth_api.get_current_user()" ] }, { @@ -574,7 +678,7 @@ "metadata": {}, "outputs": [], "source": [ - "admin1Client.auth.create_policy(\n", + "admin1Client.auth_api.create_policy(\n", " policy=models.Policy(\n", " id='FSBlockMergingToMain',\n", " statement=[models.Statement(\n", @@ -598,12 +702,12 @@ { "cell_type": "code", "execution_count": null, - "id": "bd383a1f-140a-49a1-9240-4a4b744cb3ca", + "id": "b4e2964c-968a-476e-a636-8c2097181380", "metadata": {}, "outputs": [], "source": [ - "admin1Client.auth.attach_policy_to_group(\n", - " group_id='DataScientists',\n", + "admin1Client.auth_api.attach_policy_to_group(\n", + " group_id=DataScientistsGroup.id,\n", " policy_id='FSBlockMergingToMain')" ] }, @@ -622,12 +726,12 @@ "metadata": {}, "outputs": [], "source": [ - "admin1Client.auth.create_policy(\n", + "admin1Client.auth_api.create_policy(\n", " policy=models.Policy(\n", " id='FSBlockAccessToPIIData',\n", " statement=[models.Statement(\n", " effect=\"deny\",\n", - " resource=\"arn:lakefs:fs:::repository/\"+repo+\"/object/PII/*\",\n", + " resource=\"arn:lakefs:fs:::repository/\"+repo_name+\"/object/PII/*\",\n", " action=[\"fs:*\"],\n", " ),\n", " ]\n", @@ -650,8 +754,8 @@ "metadata": {}, "outputs": [], "source": [ - "admin1Client.auth.attach_policy_to_group(\n", - " group_id='Developers',\n", + "admin1Client.auth_api.attach_policy_to_group(\n", + " group_id=groupIdDevelopers,\n", " policy_id='FSBlockAccessToPIIData')" ] }, @@ -666,15 +770,15 @@ { "cell_type": "code", "execution_count": null, - "id": "19a4d613-f76d-497d-844d-21aadf1fc50e", - "metadata": {}, + "id": "7211351b-9df6-4996-bc77-96f1ad407ef4", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "admin1Client.repositories.create_repository(\n", - " repository_creation=models.RepositoryCreation(\n", - " name=repo,\n", - " storage_namespace=storageNamespace,\n", - " default_branch=sourceBranch))" + "repo = lakefs.Repository(repo_name, client=admin1LakefsClient).create(storage_namespace=f\"{storageNamespace}/{repo_name}\", default_branch=sourceBranch, exist_ok=True)\n", + "branchMain = repo.branch(sourceBranch)\n", + "print(repo)" ] }, { @@ -692,8 +796,8 @@ "metadata": {}, "outputs": [], "source": [ - "admin1Client.repositories.set_branch_protection_rules(\n", - " repository=repo,\n", + "admin1Client.repositories_api.set_branch_protection_rules(\n", + " repository=repo_name,\n", " branch_protection_rule=[models.BranchProtectionRule(\n", " pattern=sourceBranch)])" ] @@ -709,16 +813,14 @@ { "cell_type": "code", "execution_count": null, - "id": "d2c1d011-b1ae-444b-88da-bf79f5eb00b8", - "metadata": {}, + "id": "0f68f53e-1a7c-4c96-acee-abf6d28463e5", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "import os\n", - "contentToUpload = open('/data/'+fileName, 'rb') # Only a single file per upload which must be named \\\\\\\"content\\\\\\\"\n", - "admin1Client.objects.upload_object(\n", - " repository=repo,\n", - " branch=sourceBranch,\n", - " path='PII/'+fileName, content=contentToUpload)" + "contentToUpload = open(f\"/data/{fileName}\", 'r').read()\n", + "branchMain.object('PII/'+fileName).upload(data=contentToUpload, mode='wb', pre_sign=False)" ] }, { @@ -732,15 +834,14 @@ { "cell_type": "code", "execution_count": null, - "id": "85069913-4964-4c22-a516-8a5637e7d606", - "metadata": {}, + "id": "8d48e4f3-7e26-49c2-afcf-2f34fc6ba3a8", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "admin1Client.branches.create_branch(\n", - " repository=repo,\n", - " branch_creation=models.BranchCreation(\n", - " name='ingest-pii-data',\n", - " source=sourceBranch))" + "branchIngestPIIData = repo.branch('ingest-pii-data').create(source_reference=sourceBranch)\n", + "print(\"ingest-pii-data ref:\", branchIngestPIIData.get_commit().id)" ] }, { @@ -754,16 +855,14 @@ { "cell_type": "code", "execution_count": null, - "id": "72d95d4f-c02b-4c3d-9a5b-a58abb651dd9", - "metadata": {}, + "id": "c243e371-cefa-4188-b170-801121f62b2e", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "import os\n", - "contentToUpload = open('/data/'+fileName, 'rb') # Only a single file per upload which must be named \\\\\\\"content\\\\\\\"\n", - "admin1Client.objects.upload_object(\n", - " repository=repo,\n", - " branch='ingest-pii-data',\n", - " path='PII/'+fileName, content=contentToUpload)" + "contentToUpload = open(f\"/data/{fileName}\", 'r').read()\n", + "branchIngestPIIData.object('PII/'+fileName).upload(data=contentToUpload, mode='wb', pre_sign=False)" ] }, { @@ -777,16 +876,14 @@ { "cell_type": "code", "execution_count": null, - "id": "87b1708e-7d0a-413c-85c9-d5266cde2e20", - "metadata": {}, + "id": "d6340672-cd51-4d83-b3af-7372739051f1", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "admin1Client.commits.commit(\n", - " repository=repo,\n", - " branch='ingest-pii-data',\n", - " commit_creation=models.CommitCreation(\n", - " message='Added PII file!',\n", - " metadata={'using': 'python_api'}))" + "ref = branchIngestPIIData.commit(message='Added PII file!', metadata={'using': 'python_sdk'})\n", + "print_commit(ref.get_commit())" ] }, { @@ -800,14 +897,14 @@ { "cell_type": "code", "execution_count": null, - "id": "9bf0e5b2-4a87-404f-8144-12f4a94c133a", - "metadata": {}, + "id": "b00c062d-4a4d-4e84-9276-6e2a3c7ed791", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "admin1Client.refs.merge_into_branch(\n", - " repository=repo,\n", - " source_ref='ingest-pii-data', \n", - " destination_branch=sourceBranch)" + "res = branchIngestPIIData.merge_into(branchMain)\n", + "print(res)" ] }, { @@ -821,14 +918,13 @@ { "cell_type": "code", "execution_count": null, - "id": "1dfb0e05-769a-4be8-ac13-646b878952c4", - "metadata": {}, + "id": "25edb53f-bdce-45e7-af6c-c1f71d9d0f59", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "admin1Client.objects.get_object(\n", - " repository=repo,\n", - " ref='main',\n", - " path='PII/'+fileName).read()" + "lakefs.Repository(repo_name, client=admin1LakefsClient).branch(sourceBranch).object(path='PII/'+fileName).reader(mode='r').read()" ] }, { @@ -842,14 +938,13 @@ { "cell_type": "code", "execution_count": null, - "id": "98248998-7d82-4aa4-aa94-c35e38893e16", - "metadata": {}, + "id": "c778b73c-7e74-4716-b615-050d2a230f66", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "data_scientist1Client.objects.get_object(\n", - " repository=repo,\n", - " ref='main',\n", - " path='PII/'+fileName).read()" + "lakefs.Repository(repo_name, client=data_scientist1LakeFSClient).branch(sourceBranch).object(path='PII/'+fileName).reader(mode='r').read()" ] }, { @@ -863,14 +958,13 @@ { "cell_type": "code", "execution_count": null, - "id": "070772b7-2c6e-403d-bc0f-168053a916c3", - "metadata": {}, + "id": "f54665ec-022c-4e53-ad23-209a2e2b3ecc", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "developer1Client.objects.get_object(\n", - " repository=repo,\n", - " ref='main',\n", - " path='PII/'+fileName).read()" + "lakefs.Repository(repo_name, client=developer1LakeFSClient).branch(sourceBranch).object(path='PII/'+fileName).reader(mode='r').read()" ] }, { @@ -884,15 +978,14 @@ { "cell_type": "code", "execution_count": null, - "id": "c237341b-b427-41d3-af8e-2268568256c2", - "metadata": {}, + "id": "ede96885-d05f-4b6b-8aec-8b212c3304f3", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "data_scientist1Client.branches.create_branch(\n", - " repository=repo,\n", - " branch_creation=models.BranchCreation(\n", - " name='ds_branch',\n", - " source=sourceBranch))" + "branchDSBranch = lakefs.Repository(repo_name, client=data_scientist1LakeFSClient).branch('ds_branch').create(source_reference=sourceBranch)\n", + "print(\"ds_branch ref:\", branchDSBranch.get_commit().id)" ] }, { @@ -906,16 +999,14 @@ { "cell_type": "code", "execution_count": null, - "id": "b683cc3d-1be4-494f-8cba-754888f3e2ea", - "metadata": {}, + "id": "1ee6e6f3-6dc5-4ff3-b915-b10ccddee652", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "import os\n", - "contentToUpload = open('/data/lakefs_test_new.csv', 'rb') # Only a single file per upload which must be named \\\\\\\"content\\\\\\\"\n", - "data_scientist1Client.objects.upload_object(\n", - " repository=repo,\n", - " branch='ds_branch',\n", - " path='ds/lakefs_test_new.csv', content=contentToUpload)" + "contentToUpload = open('/data/lakefs_test_new.csv', 'r').read()\n", + "branchDSBranch.object('ds/lakefs_test_new.csv').upload(data=contentToUpload, mode='wb', pre_sign=False)" ] }, { @@ -929,16 +1020,14 @@ { "cell_type": "code", "execution_count": null, - "id": "d86de9b6-544d-4b4a-a1b0-b92384f55163", - "metadata": {}, + "id": "694b9af0-738b-4f1c-9269-c295aae62343", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "data_scientist1Client.commits.commit(\n", - " repository=repo,\n", - " branch='ds_branch',\n", - " commit_creation=models.CommitCreation(\n", - " message='Added new data file!',\n", - " metadata={'using': 'python_api'}))" + "ref = branchDSBranch.commit(message='Added new data file!', metadata={'using': 'python_sdk'})\n", + "print_commit(ref.get_commit())" ] }, { @@ -952,14 +1041,13 @@ { "cell_type": "code", "execution_count": null, - "id": "166e0025-1107-453e-933f-6c9345247110", - "metadata": {}, + "id": "59c5734b-ea8d-417b-8d73-225fbd31beb3", + "metadata": { + "tags": [] + }, "outputs": [], "source": [ - "data_scientist1Client.refs.merge_into_branch(\n", - " repository=repo,\n", - " source_ref='ds_branch', \n", - " destination_branch=sourceBranch)" + "branchDSBranch.merge_into(sourceBranch)" ] }, {