Public packages
Add packages from PyPI with their name and version:==) so every run installs the same code. A package without a pinned version is installed once and reused until the notebook’s dependencies change, so runs don’t pick up its new releases. When you save, Nekt checks that each package exists on PyPI and rejects the ones it can’t find.
Private packages
To share code across notebooks, put it in a Python package in a private Git repository and install it as a dependency. Private repositories need credentials, which you store as a Secret and reference by key instead of writing them into the dependency. Reference a secret as${KEY}, where KEY is the secret’s key:
1
Create a token for the repository
Use a token that can only read the repository. On GitHub, create a fine-grained personal access token with access to that repository only and the Contents: Read-only repository permission.
2
Store the token as a secret
In Secrets, create a secret whose value is the token, for example with the key
GITHUB_TOKEN. A key used in a reference may contain only letters, digits, and underscores, and must not start with a digit.3
Add the dependency
Add the dependency in the
git+https://${KEY}@host/owner/repository.git@ref format. Set ref to a tag, branch, or commit.4
Save the notebook
Nekt checks that the secret exists, that you can read it, and that the repository and
ref can be reached with its value.Branches, tags, and commits
Whatref points at decides when the notebook picks up new code:
For a branch, a tag, or no
ref, Nekt checks the repository for a new commit when each run starts. A run after a push installs the new commit. On a PySpark notebook, a new commit makes the run rebuild the notebook’s image before it starts, which adds a few minutes to that run only. PyPI packages are not checked: they install at the versions listed.
The run log shows the check as one line when it starts and one summary when it ends:
When the check fails
What happens depends on whether the problem can fix itself:
A failed check stops the run before its code runs, so no data is written.
How secrets in dependencies are handled
- Access: You can only reference secrets you have permission to read. Saving a notebook that references any other secret fails, whether the secret is missing or you lack permission.
- Linking: A secret referenced in a dependency is added to the notebook’s secrets, the same way as a secret your code loads with
load_secret. - Deletion: A secret a notebook uses can’t be deleted. The error lists the notebooks that use it. Remove the reference from their code and dependencies first.
- Storage: The notebook stores only the
${KEY}reference. The value is read when dependencies are installed, so rotating the secret needs no change to the notebook. - Exposure: The secret’s value is used only to install the package. Your notebook code can’t read it from the environment, and the value is masked in run logs.
The
git+https:// scheme is the only one supported for Git dependencies. SSH URLs (git+ssh://) are rejected.Other Git hosts
Any Git host that accepts a token over HTTPS works. Put the token where the host expects it in the URL. For example, on GitLab:Spark jars
PySpark notebooks can also add Spark jars: Maven Central coordinates in thegroup:artifact:version format, added to Spark’s classpath.