python
Provides lint, test, format check, security scan, and Docker image buildfunctions for Python projects. Uses ruff for linting/formatting,
pytest for testing, and bandit for security scanning.
Installation
dagger install github.com/stuttgart-things/dagger/python@v0.86.0Entrypoint
Return Type
Python Example
dagger -m github.com/stuttgart-things/dagger/python@2dc146fd7c32848394ea4b5e5b7e66b920035233 call \
func (m *MyModule) Example() *dagger.Python {
return dag.
Python()
}@function
def example() -> dagger.Python:
return (
dag.python()
)@func()
example(): Python {
return dag
.python()
}Types
Python 🔗
buildAndPushImage() 🔗
BuildAndPushImage builds and pushes a Docker image to a registry
Return Type
String !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| src | Directory ! | - | Build context directory |
| imageRef | String ! | - | Full image reference (e.g., ghcr.io/org/image:tag) |
| token | Secret ! | - | Registry authentication token |
| dockerfile | String | "Dockerfile" | No description provided |
| version | String | "dev" | No description provided |
| commit | String | "unknown" | No description provided |
| date | String | "unknown" | No description provided |
| registryUrl | String | "ghcr.io" | No description provided |
| username | String | "" | No description provided |
Example
dagger -m github.com/stuttgart-things/dagger/python@2dc146fd7c32848394ea4b5e5b7e66b920035233 call \
build-and-push-image --src DIR_PATH --image-ref string --token env:MYSECRETfunc (m *MyModule) Example(ctx context.Context, src *dagger.Directory, imageRef string, token *dagger.Secret) string {
return dag.
Python().
BuildAndPushImage(ctx, src, imageRef, token)
}@function
async def example(src: dagger.Directory, image_ref: str, token: dagger.Secret) -> str:
return await (
dag.python()
.build_and_push_image(src, image_ref, token)
)@func()
async example(src: Directory, imageRef: string, token: Secret): Promise<string> {
return dag
.python()
.buildAndPushImage(src, imageRef, token)
}buildImage() 🔗
BuildImage builds a Docker image from a Dockerfile
Return Type
Container !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| src | Directory ! | - | Build context directory (must contain Dockerfile) |
| dockerfile | String | "Dockerfile" | No description provided |
| version | String | "dev" | No description provided |
| commit | String | "unknown" | No description provided |
| date | String | "unknown" | No description provided |
Example
dagger -m github.com/stuttgart-things/dagger/python@2dc146fd7c32848394ea4b5e5b7e66b920035233 call \
build-image --src DIR_PATHfunc (m *MyModule) Example(src *dagger.Directory) *dagger.Container {
return dag.
Python().
BuildImage(src)
}@function
def example(src: dagger.Directory) -> dagger.Container:
return (
dag.python()
.build_image(src)
)@func()
example(src: Directory): Container {
return dag
.python()
.buildImage(src)
}formatCheck() 🔗
FormatCheck runs ruff format check (non-modifying) on Python source code
Return Type
String !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| src | Directory ! | - | Python source directory |
| pythonVersion | String | "3.12-slim" | No description provided |
| ruffVersion | String | "0.8.6" | No description provided |
| paths | String | "src/,tests/" | Comma-separated list of paths to check |
Example
dagger -m github.com/stuttgart-things/dagger/python@2dc146fd7c32848394ea4b5e5b7e66b920035233 call \
format-check --src DIR_PATHfunc (m *MyModule) Example(ctx context.Context, src *dagger.Directory) string {
return dag.
Python().
FormatCheck(ctx, src)
}@function
async def example(src: dagger.Directory) -> str:
return await (
dag.python()
.format_check(src)
)@func()
async example(src: Directory): Promise<string> {
return dag
.python()
.formatCheck(src)
}lint() 🔗
Lint runs ruff linter on Python source code
Return Type
String !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| src | Directory ! | - | Python source directory |
| pythonVersion | String | "3.12-slim" | No description provided |
| ruffVersion | String | "0.8.6" | No description provided |
| paths | String | "src/,tests/" | Comma-separated list of paths to lint |
Example
dagger -m github.com/stuttgart-things/dagger/python@2dc146fd7c32848394ea4b5e5b7e66b920035233 call \
lint --src DIR_PATHfunc (m *MyModule) Example(ctx context.Context, src *dagger.Directory) string {
return dag.
Python().
Lint(ctx, src)
}@function
async def example(src: dagger.Directory) -> str:
return await (
dag.python()
.lint(src)
)@func()
async example(src: Directory): Promise<string> {
return dag
.python()
.lint(src)
}securityScan() 🔗
SecurityScan runs bandit Python security scanner
Return Type
String !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| src | Directory ! | - | Python source directory |
| pythonVersion | String | "3.12-slim" | No description provided |
| banditVersion | String | "1.8.3" | No description provided |
| scanPath | String | "src/" | Path to scan |
Example
dagger -m github.com/stuttgart-things/dagger/python@2dc146fd7c32848394ea4b5e5b7e66b920035233 call \
security-scan --src DIR_PATHfunc (m *MyModule) Example(ctx context.Context, src *dagger.Directory) string {
return dag.
Python().
SecurityScan(ctx, src)
}@function
async def example(src: dagger.Directory) -> str:
return await (
dag.python()
.security_scan(src)
)@func()
async example(src: Directory): Promise<string> {
return dag
.python()
.securityScan(src)
}test() 🔗
Test runs pytest on the Python source code
Return Type
String !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| src | Directory ! | - | Python source directory |
| pythonVersion | String | "3.12-slim" | No description provided |
| testPath | String | "tests/" | Path to test directory |
| installExtra | String | "" | Extra pip install specifier (e.g., ".[dev]" or "-r requirements-dev.txt") |
Example
dagger -m github.com/stuttgart-things/dagger/python@2dc146fd7c32848394ea4b5e5b7e66b920035233 call \
test --src DIR_PATHfunc (m *MyModule) Example(ctx context.Context, src *dagger.Directory) string {
return dag.
Python().
Test(ctx, src)
}@function
async def example(src: dagger.Directory) -> str:
return await (
dag.python()
.test(src)
)@func()
async example(src: Directory): Promise<string> {
return dag
.python()
.test(src)
}testWithCoverage() 🔗
TestWithCoverage runs pytest with coverage reporting
Return Type
String !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| src | Directory ! | - | Python source directory |
| pythonVersion | String | "3.12-slim" | No description provided |
| testPath | String | "tests/" | Path to test directory |
| installExtra | String | "" | Extra pip install specifier |
| coveragePath | String | "src/" | Source path for coverage measurement |
Example
dagger -m github.com/stuttgart-things/dagger/python@2dc146fd7c32848394ea4b5e5b7e66b920035233 call \
test-with-coverage --src DIR_PATHfunc (m *MyModule) Example(ctx context.Context, src *dagger.Directory) string {
return dag.
Python().
TestWithCoverage(ctx, src)
}@function
async def example(src: dagger.Directory) -> str:
return await (
dag.python()
.test_with_coverage(src)
)@func()
async example(src: Directory): Promise<string> {
return dag
.python()
.testWithCoverage(src)
}