Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
73c580c
support for cloning repositories using git 🐑
soustruh Jun 3, 2025
3a32dc9
fix script excerpt & log it again
soustruh Jun 3, 2025
e81f2f1
adding cloned repository root to sys.path for predictable imports 💡
soustruh Jun 3, 2025
2134795
UI for configuring git repository
soustruh Jun 17, 2025
d38f02c
deploy in a test component
soustruh Jun 17, 2025
e79f278
letter case in UI
soustruh Jun 18, 2025
2e86494
list branches sync action
soustruh Jun 18, 2025
7cf4556
create root's .ssh directory for running sync actions
soustruh Jun 18, 2025
ff2312d
include workflow run number in image tag
soustruh Jun 18, 2025
0030779
list files sync action
soustruh Jun 18, 2025
822ced4
ignore flake8's false positives caused by ruff
soustruh Jun 18, 2025
4f11ef4
cleanup 🧹
soustruh Jun 18, 2025
ff02d70
description of the updated configuration related to git support
soustruh Jun 23, 2025
8c6f87d
minor changes in wording
soustruh Jun 25, 2025
726cd7a
REPO_PATH is a class variable now
soustruh Jun 25, 2025
e242418
package installation refactoring
soustruh Jun 25, 2025
f8bf79a
fix unexpected sync action failure & reduce code redundancy
soustruh Jun 25, 2025
54f8e59
cleanup 🧹
soustruh Jul 4, 2025
5d285a1
dynamic version (specified elsewhere)
soustruh Jul 4, 2025
3d32294
package update 📦
soustruh Jul 4, 2025
348316b
clickable link to example/template repository 🧩
soustruh Jul 4, 2025
0839b9b
isolated python environments ☃️
soustruh Jul 8, 2025
9f7d04a
updated UI for python environments 🐍
soustruh Jul 8, 2025
5f66b05
fix os.path → pathlib refactor (forgotten .name)
soustruh Jul 8, 2025
cbc283c
exclude workflow run number from image tag again (not needed anymore)
soustruh Jul 8, 2025
128ed92
fix package installation for certain scenarios 📦
soustruh Jul 9, 2025
a30828f
correct permissions for preinstalled python versions
soustruh Jul 9, 2025
376ef5b
tests for local development 🧑‍💻
soustruh Jul 9, 2025
7c29894
use base image's python environment for old configurations with no `v…
soustruh Jul 9, 2025
4ffac93
fixed forgotten & misleading default error messages
soustruh Jul 10, 2025
d6ea563
Revert "deploy in a test component"
soustruh Jul 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ on:
concurrency: ci-${{ github.ref }} # to avoid tag collisions in the ECR
env:
# repository variables:
KBC_DEVELOPERPORTAL_APP: "kds-team.app-custom-python" # replace with your component id
KBC_DEVELOPERPORTAL_VENDOR: "kds-team" # replace with your vendor
KBC_DEVELOPERPORTAL_APP: "kds-team.app-custom-python"
KBC_DEVELOPERPORTAL_VENDOR: "kds-team"
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
KBC_DEVELOPERPORTAL_USERNAME: "kds-team+github"

Expand Down Expand Up @@ -230,4 +230,4 @@ jobs:
- name: Update developer portal properties
run: |
chmod +x scripts/developer_portal/*.sh
scripts/developer_portal/update_properties.sh
scripts/developer_portal/update_properties.sh
12 changes: 12 additions & 0 deletions .ssh/known_hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# In case public repositories update their keys, the component will start failing with:
# Host key verification failed.
# fatal: Could not read from remote repository.
#
# In such case, retrieve the new keys using the following command:
# ssh-keyscan -t ed25519 github.com

# github.com:22 SSH-2.0-f892a94b
github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl

# bitbucket.org:22 SSH-2.0-conker_74c0242eb7-dirty 787a0a0e3e79
bitbucket.org ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIazEu89wgQZ4bqs3d63QSMzYVa0MuJ2e2gKTKqu+UUO
18 changes: 17 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,25 @@ ENV UV_CACHE_DIR="/.cache/uv"
# Using the same path as venv defined in the base image so we can use all the preinstalled packages
ENV UV_PROJECT_ENVIRONMENT="/home/default/"

# Run uv sync as uid/gid 1000 so we don't have to chown the /home/default directory with 100k files =-O
# Preinstall other Python versions for creating isolated virtual environments
USER 1000:1000
RUN uv python install 3.12
RUN uv python install 3.13
RUN uv python install 3.14

# Add Github SSH host key to known_hosts file & create .bash_aliases for convenience when debugging
USER 1000:1000
RUN mkdir /home/${USERNAME}/.ssh
COPY .ssh/known_hosts /home/${USERNAME}/.ssh/known_hosts
RUN echo "alias l='ls -Al --group-directories-first'" >> /home/${USERNAME}/.bash_aliases

# Create root's .ssh directory for storing SSH keys when running sync actions
USER root
RUN mkdir /root/.ssh
COPY .ssh/known_hosts /root/.ssh/known_hosts

# Run uv sync as uid/gid 1000 so we don't have to chown the /home/default directory with 100k files =-O
USER 1000:1000
WORKDIR /code/
COPY pyproject.toml .
COPY uv.lock .
Expand Down
89 changes: 75 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,76 @@
- [Custom Python Component](#custom-python-component)
- [Configuration](#configuration)
- [Git configuration](#git-configuration)
- [SSH configuration](#ssh-configuration)
- [Example: Running code saved in custom repository + template 🧩](#example-running-code-saved-in-custom-repository--template-)
- [Example: Listing preinstalled packages](#example-listing-preinstalled-packages)
- [Example: Accessing custom configuration parameters](#example-accessing-custom-configuration-parameters)
- [Development](#development)
- [Integration](#integration)


# Custom Python Component

This component lets you run your own Python code directly within Keboola, with support for custom dependencies configured via the UI.


## Configuration

- `code`: JSON encoded Python code to run.
- `packages`: Array of extra packages to be installed.
- `source`: Source of the code to run.
- `code`: Custom code entered in a text field (default).
- `git`: Custom repository.
- `user_properties`: Object containing custom configuration parameters. The key names prefixed with `#` will be encrypted upon saving.
- `git`: Object containing configuration of the git repository, which shall be cloned and run (`"source": "git"` only).
- `code`: JSON encoded Python code to run (`"source": "code"` only).
- `packages`: Array of extra packages to be installed (`"source": "code"` only). *If you're not sure whether you need to install certain package or not, you can run the command `uv pip list` via subprocess (see the example below).*


### Git configuration

The git configuration object supports the following parameters:

- `url`: Repository URL – supports both HTTPS and SSH formats.
- `branch`: Branch name to checkout – UI provides branch selection.
- `filename`: Python script filename to execute – UI lists available files.
- `auth`: Repository visibility & authentication method.
- `none`: Public repository, no authentication (default).
- `pat`: Private repository, Personal Access Token.
- `ssh`: Private repository, SSH key.
- `#token`: Personal Access Token (`"auth": "pat"` only). This value will be encrypted in Keboola Storage.
- `ssh_keys`: SSH keys configuration object (`"auth": "ssh"` only).


### SSH configuration

- `keys`: Object containing both public and private keys.
- `public`: Public key saved in your Git project. This value is not passed by the component and is saved just for future reference.
- `#private`: Private key used for authentication. This value will be encrypted in Keboola Storage.


### Example: Running code saved in custom repository + template 🧩

As this might become a preferred way of running custom Python code in Keboola for many, we prepared a [simple example project](https://github.com/keboola/component-custom-python-example-repo-1), which help you with your first steps (and can also server you as a template for any of your future projects).


Contents of the `config.json` file:

```json
{
"parameters": {
"source": "git",
"git": {
"url": "https://github.com/keboola/component-custom-python-example-repo-1.git",
"branch": "main",
"filename": "main.py",
"auth": "none",
},
"user_properties": {
"debug": true
}
}
}
```

If you're not sure whether you need to install certain package or not, you can run the command `uv pip list` via subprocess (see the example below).


### Example: Listing preinstalled packages
Expand All @@ -29,10 +90,10 @@ The above code in the `config.json` file format for local testing:

```json
{
"parameters": {
"code": "import datetime\nimport subprocess\n\nprint(\"Hello world!\")\nprint(\"Current date and time:\", datetime.datetime.now())\nprint(\"See the full list of preinstalled packages:\")\n\nsubprocess.check_call([\"uv\", \"pip\", \"list\"])\n",
"packages": []
}
"parameters": {
"code": "import datetime\nimport subprocess\n\nprint(\"Hello world!\")\nprint(\"Current date and time:\", datetime.datetime.now())\nprint(\"See the full list of preinstalled packages:\")\n\nsubprocess.check_call([\"uv\", \"pip\", \"list\"])\n",
"packages": []
}
}
```

Expand All @@ -53,14 +114,14 @@ The above code in the `config.json` file format for local testing:

```json
{
"parameters": {
"code": "from keboola.component import CommonInterface\n\nci = CommonInterface()\n# access user parameters\nprint(ci.configuration.parameters)",
"packages": [],
"user_properties": {
"debug": false
"#secretCredentials": "theStrongestPasswordEver"
}
"parameters": {
"code": "from keboola.component import CommonInterface\n\nci = CommonInterface()\n# access user parameters\nprint(ci.configuration.parameters)",
"packages": [],
"user_properties": {
"debug": false
"#secretCredentials": "theStrongestPasswordEver"
}
}
}
```

Expand Down
223 changes: 0 additions & 223 deletions TEMPLATE_README.md

This file was deleted.

Loading