GitHub import

Import external packages for use in your code files
The fundamental purpose of GitHub import is to give files within your Baseten applications access to code managed separately on GitHub. This way, you don't have to copy in business logic or parsing scripts, just write simple wrappers to expose this code to your models and applications.
GitHub import is a feature on paid plans and is not enabled by default. Upgrade to a paid Baseten plan to enable this feature in your Baseten workspace.
Your workspace must also have the draft environment enabled.

Setting up the GitHub integration

In order to use GitHub import, you must first enable the GitHub integration under the "Integrations" tab of the workspace settings. You must be a workspace admin to complete this action. View complete setup instructions:

Using GitHub import

Again, the purpose of GitHub import is bringing outside code into your Baseten apps. Think of it like installing packages from PyPi, but without the hassle of making your code pip installable. Instead, with GitHub import, you can add code from your GitHub to your application's Python environment and use it in your files.
Essentially, this means that you will be able to import code from your GitHub repositories into your Baseten applications.

Adding repositories

The imported repositories tab
To add a repository to your application, click the + next to "imported repositories" to open a browser with your linked GitHub repositories. If there are repos in your GitHub organization that aren’t available for import, you may need to grant the GitHub Baseten app access to those specific repos. Or if you just created the repository on GitHub and it is not showing up in the repository list, try refreshing the page to give the GitHub integration a change to reload your repositories.
Listing imported repositories
When you select and import a repository, it may take a couple of minutes for the repository to be fully available. Once loaded, the you'll have access to the main/default branch of the repository in question.
When you add a repository to an application, it is only available for that application. Each application handles GitHub import separately.

Using code from added repositories

Consider the following repository structure:
- my_modules/
- bar/
- foo/
We want to import an object FooUtils from the file at my_modules/foo/ to use in our code file in a Baseten application. We also want to import the Bar object from my_modules/bar/ This is accomplished with a standard import statement:
from import FooUtils
from import Bar

Setting the Python root

When you import a repository, we automatically add the root of the repository to your Python path. If your repository uses a subdirectory, for example ./my_modules, within the repo as its Python root, you can customize the path like so:
sys.path.append(os.path.join(context.path_for_imported_repo("my_github/my_project"), "my_modules"))
from foo.foo_utils import FooUtils
from import Bar
The imported code will work exactly the same.
You can also access files from the repository via the context object.
def print_imported_file_path(block_input, context, env):
Or, if you are im

Syncing and publishing changes

When you make changes to code on GitHub, you'll need to pull those changes into your Baseten apps. This is handled with the detail view that expands from each imported repository.
Repository details
Once changes are pulled, they must be published along with any other changes to the application. Adding, pulling, and deleting repositories gets reflected in the publish dialog.
Repository changes included in the publish dialog

Removing repositories

You can delete repositories from your applications at any time. This change will be captured in the version history upon publishing the app. You can also disconnect the GitHub integration at any time.
If you delete the repository or an actively used commit on GitHub, but not on Baseten, this leads to somewhat unspecified behavior. Things may work temporarily, but as your application's Python environment is refreshed, it will be unable to clone the desired repository, and the repository will have to be manually removed before the application will function. So please do not delete repositories or in-use commits without first removing them from your Baseten application.

Implementation notes

Integrating with GitHub and importing code into your Python environment gives rise to a few edge cases that are documented here in case you run into them.

Git submodules

We do not recursively clone git submodules.

Size limit

At the moment, you cannot add a repo over 100 MB.

Managing requirements

If your imported repository has PyPi requirements, you’ll have to manually add those to your project.