Report

Simple Data Toolkit - Tutorial - Git API - Python

November 11, 2023 at 1:00 AM PST
This post has no media.
Profile picture
Franklin Powers

Simple Data Toolkit provides an unofficial API for reading files, commits, branches, and repos from the Git API. (At the time of this writing, the release of this is pending for complete support, but it is coming soon)

To retrieve all repos a user has using Simple Data Toolkit, we can do the following:


from sdtk import com_sdtk_api_GitAPI

def printer(data, reader):
print(reader.toArrayOfNativeMaps(None))

com_sdtk_api_GitAPI.reposAPI().retrieveData({"owner": "Vis-LLC"}, printer)



To retrieve all branches a repo has using Simple Data Toolkit, we can do the following:


from sdtk import com_sdtk_api_GitAPI

def printer(data, reader):
print(reader.toArrayOfNativeMaps(None))

com_sdtk_api_GitAPI.branchesAPI().retrieveData({"owner": "Vis-LLC", "repo": "Simple-Data-Toolkit"}, printer)


To retrieve all the files in a branch using Simple Data Toolkit, we can do the following:


from sdtk import com_sdtk_api_GitAPI

def printer(data, reader):
print(reader.toArrayOfNativeMaps(None))

com_sdtk_api_GitAPI.filesAPI().retrieveData({"owner": "Vis-LLC", "repo": "Simple-Data-Toolkit", "branch": "main"}, printer)


To retrieve the data in a file using Simple Data Toolkit, we can do the following:


from sdtk import com_sdtk_api_GitAPI

def printerData(data, reader):
print(data)

com_sdtk_api_GitAPI.retrieveAPI().retrieveData({"owner": "Vis-LLC", "repo": "Simple-Data-Toolkit-UI", "branch": "main", "path": "index.html"}, printerData)


We can also login using a personal access token (https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)


from sdtk import com_sdtk_api_GitAPI

def printerData(data, reader):
print(data)

com_sdtk_api_GitAPI.instance().setKey("Personal Access Token Here").retrieveAPI().retrieveData({"owner": "Vis-LLC", "repo": "Simple-Data-Toolkit-UI", "branch": "main", "path": "index.html"}, printerData)

Any thoughts on Franklin's post?

To comment or reply, you need an Ortingo account.

Sign in or sign up

Here's what Ortingoers think of Franklin's post.

There are no comments on this post.