Skip to main content
Prefect-github makes it easy to interact with GitHub repositories and use GitHub credentials.

Getting started

Prerequisites

Install prefect-github

The following command will install a version of prefect-github compatible with your installed version of prefect. If you don’t already have prefect installed, it will install the newest version of prefect as well.
Upgrade to the latest versions of prefect and prefect-github:

Register newly installed block types

Register the block types in the prefect-github module to make them available for use.

Examples

In the examples below, you create blocks with Python code. Alternatively, blocks can be created through the Prefect UI. To create a deployment and run a deployment where the flow code is stored in a private GitHub repository, you can use the GitHubCredentials block. A deployment can use flow code stored in a GitHub repository without using this library in either of the following cases:
  • The repository is public
  • The deployment uses a Secret block to store the token
Code to create a GitHub Credentials block:

Access flow code stored in a private GitHub repository in a deployment

Use the credentials block you created above to pass the GitHub access token during deployment creation. The code below assumes there’s flow code stored in a private GitHub repository.
Alternatively, if you use a prefect.yaml file to create the deployment, reference the GitHub Credentials block in the pull step:

Interact with a GitHub repository

You can use prefect-github to create and retrieve issues and PRs from a repository. Here’s an example of adding a star to a GitHub repository:

Resources

For assistance using GitHub, consult the GitHub documentation. Refer to the prefect-github SDK documentation to explore all the capabilities of the prefect-github library.