python-sdk
Runtime module for the Python SDK
Installation
dagger install github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4
Entrypoint
Return Type
PythonSdk !
Arguments
Name | Type | Description |
---|---|---|
sdkSourceDir | Directory | Directory with the Python SDK source code. |
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
func (m *myModule) example() *PythonSdk {
return dag.
PythonSdk()
}
@function
def example() -> dag.PythonSdk:
return (
dag.python_sdk()
)
@func()
example(): PythonSdk {
return dag
.pythonSdk()
}
Types
PythonSdk 🔗
Functions for building the runtime module for the Python SDK. The server interacts directly with the ModuleRuntime and Codegen functions. The others were built to be composable and chainable to facilitate the creation of extension modules (custom SDKs that depend on this one).
sdkSourceDir() 🔗
Directory with the Python SDK source code
Return Type
Directory !
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
sdk-source-dir
func (m *myModule) example() *Directory {
return dag.
PythonSdk().
SdkSourceDir()
}
@function
def example() -> dagger.Directory:
return (
dag.python_sdk()
.sdk_source_dir()
)
@func()
example(): Directory {
return dag
.pythonSdk()
.sdkSourceDir()
}
requiredPaths() 🔗
List of patterns to always include when loading Python modules
Return Type
[String ! ] !
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
required-paths
func (m *myModule) example(ctx context.Context) []string {
return dag.
PythonSdk().
RequiredPaths(ctx)
}
@function
async def example() -> List[str]:
return await (
dag.python_sdk()
.required_paths()
)
@func()
async example(): Promise<string[]> {
return dag
.pythonSdk()
.requiredPaths()
}
container() 🔗
Resulting container after each composing step
Return Type
Container !
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
container
func (m *myModule) example() *Container {
return dag.
PythonSdk().
Container()
}
@function
def example() -> dagger.Container:
return (
dag.python_sdk()
.container()
)
@func()
example(): Container {
return dag
.pythonSdk()
.container()
}
codegen() 🔗
Generated code for the Python module
Return Type
GeneratedCode !
Arguments
Name | Type | Default Value | Description |
---|---|---|---|
modSource | ModuleSource ! | - | No description provided |
introspectionJson | File ! | - | No description provided |
Example
echo 'Custom types are not supported in shell examples'
func (m *myModule) example(modSource *ModuleSource, introspectionJson *File) *GeneratedCode {
return dag.
PythonSdk().
Codegen(modSource, introspectionJson)
}
@function
def example(mod_source: dag.ModuleSource, introspection_json: dagger.File) -> dag.GeneratedCode:
return (
dag.python_sdk()
.codegen(mod_source, introspection_json)
)
@func()
example(modSource: ModuleSource, introspectionJson: File): GeneratedCode {
return dag
.pythonSdk()
.codegen(modSource, introspectionJson)
}
moduleRuntime() 🔗
Container for executing the Python module runtime
Return Type
Container !
Arguments
Name | Type | Default Value | Description |
---|---|---|---|
modSource | ModuleSource ! | - | No description provided |
introspectionJson | File ! | - | No description provided |
Example
echo 'Custom types are not supported in shell examples'
func (m *myModule) example(modSource *ModuleSource, introspectionJson *File) *Container {
return dag.
PythonSdk().
ModuleRuntime(modSource, introspectionJson)
}
@function
def example(mod_source: dag.ModuleSource, introspection_json: dagger.File) -> dagger.Container:
return (
dag.python_sdk()
.module_runtime(mod_source, introspection_json)
)
@func()
example(modSource: ModuleSource, introspectionJson: File): Container {
return dag
.pythonSdk()
.moduleRuntime(modSource, introspectionJson)
}
common() 🔗
Common steps for the ModuleRuntime and Codegen functions
Return Type
PythonSdk !
Arguments
Name | Type | Default Value | Description |
---|---|---|---|
modSource | ModuleSource ! | - | No description provided |
introspectionJson | File ! | - | No description provided |
Example
echo 'Custom types are not supported in shell examples'
func (m *myModule) example(modSource *ModuleSource, introspectionJson *File) *PythonSdk {
return dag.
PythonSdk().
Common(modSource, introspectionJson)
}
@function
def example(mod_source: dag.ModuleSource, introspection_json: dagger.File) -> dag.PythonSdk:
return (
dag.python_sdk()
.common(mod_source, introspection_json)
)
@func()
example(modSource: ModuleSource, introspectionJson: File): PythonSdk {
return dag
.pythonSdk()
.common(modSource, introspectionJson)
}
load() 🔗
Get all the needed information from the module’s metadata and source files
Return Type
PythonSdk !
Arguments
Name | Type | Default Value | Description |
---|---|---|---|
modSource | ModuleSource ! | - | No description provided |
Example
echo 'Custom types are not supported in shell examples'
func (m *myModule) example(modSource *ModuleSource) *PythonSdk {
return dag.
PythonSdk().
Load(modSource)
}
@function
def example(mod_source: dag.ModuleSource) -> dag.PythonSdk:
return (
dag.python_sdk()
.load(mod_source)
)
@func()
example(modSource: ModuleSource): PythonSdk {
return dag
.pythonSdk()
.load(modSource)
}
withBase() 🔗
Initialize the base Python container
Workdir is set to the module’s source directory.
Return Type
PythonSdk !
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
with-base
func (m *myModule) example() *PythonSdk {
return dag.
PythonSdk().
WithBase()
}
@function
def example() -> dag.PythonSdk:
return (
dag.python_sdk()
.with_base()
)
@func()
example(): PythonSdk {
return dag
.pythonSdk()
.withBase()
}
withTemplate() 🔗
Add the template files to skaffold a new module
The following files are added: - /runtime - pyproject.toml - requirements.lock - src/main/init.py
Return Type
PythonSdk !
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
with-template
func (m *myModule) example() *PythonSdk {
return dag.
PythonSdk().
WithTemplate()
}
@function
def example() -> dag.PythonSdk:
return (
dag.python_sdk()
.with_template()
)
@func()
example(): PythonSdk {
return dag
.pythonSdk()
.withTemplate()
}
withSdk() 🔗
Add the SDK package to the source directory
This includes regenerating the client bindings for the current API schema (codegen).
Return Type
PythonSdk !
Arguments
Name | Type | Default Value | Description |
---|---|---|---|
introspectionJson | File ! | - | No description provided |
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
with-sdk --introspection-json file:path
func (m *myModule) example(introspectionJson *File) *PythonSdk {
return dag.
PythonSdk().
WithSdk(introspectionJson)
}
@function
def example(introspection_json: dagger.File) -> dag.PythonSdk:
return (
dag.python_sdk()
.with_sdk(introspection_json)
)
@func()
example(introspectionJson: File): PythonSdk {
return dag
.pythonSdk()
.withSdk(introspectionJson)
}
withSource() 🔗
Add the module’s source code
Return Type
PythonSdk !
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
with-source
func (m *myModule) example() *PythonSdk {
return dag.
PythonSdk().
WithSource()
}
@function
def example() -> dag.PythonSdk:
return (
dag.python_sdk()
.with_source()
)
@func()
example(): PythonSdk {
return dag
.pythonSdk()
.withSource()
}
withInstall() 🔗
Install the module’s package and dependencies
Return Type
PythonSdk !
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
with-install
func (m *myModule) example() *PythonSdk {
return dag.
PythonSdk().
WithInstall()
}
@function
def example() -> dag.PythonSdk:
return (
dag.python_sdk()
.with_install()
)
@func()
example(): PythonSdk {
return dag
.pythonSdk()
.withInstall()
}
withoutUserConfig() 🔗
Disable the discovery of custom configuration
If it’s not necessary, it’s faster without it.
Return Type
PythonSdk !
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
without-user-config
func (m *myModule) example() *PythonSdk {
return dag.
PythonSdk().
WithoutUserConfig()
}
@function
def example() -> dag.PythonSdk:
return (
dag.python_sdk()
.without_user_config()
)
@func()
example(): PythonSdk {
return dag
.pythonSdk()
.withoutUserConfig()
}
withContainer() 🔗
Replace the underlying container
Since all steps change this container, it’s possible to extract it in one step, change it, and then set it with this function. Can be useful, for example, to add system packages between the WithBase() and WithSource() steps.
Return Type
PythonSdk !
Arguments
Name | Type | Default Value | Description |
---|---|---|---|
ctr | Container ! | - | The container to use |
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
with-container --ctr IMAGE:TAG
func (m *myModule) example(ctr *Container) *PythonSdk {
return dag.
PythonSdk().
WithContainer(ctr)
}
@function
def example(ctr: dagger.Container) -> dag.PythonSdk:
return (
dag.python_sdk()
.with_container(ctr)
)
@func()
example(ctr: Container): PythonSdk {
return dag
.pythonSdk()
.withContainer(ctr)
}
baseImage() 🔗
Image reference for the base container
Return Type
String !
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
base-image
func (m *myModule) example(ctx context.Context) string {
return dag.
PythonSdk().
BaseImage(ctx)
}
@function
async def example() -> str:
return await (
dag.python_sdk()
.base_image()
)
@func()
async example(): Promise<string> {
return dag
.pythonSdk()
.baseImage()
}
uvImage() 🔗
Image reference where uv is fetched from
Return Type
String !
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
uv-image
func (m *myModule) example(ctx context.Context) string {
return dag.
PythonSdk().
UvImage(ctx)
}
@function
async def example() -> str:
return await (
dag.python_sdk()
.uv_image()
)
@func()
async example(): Promise<string> {
return dag
.pythonSdk()
.uvImage()
}
withBaseImage() 🔗
Override the base container’s image
Needs to be called before Load.
Return Type
PythonSdk !
Arguments
Name | Type | Default Value | Description |
---|---|---|---|
ref | String ! | - | The image reference |
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
with-base-image --ref string
func (m *myModule) example(ref string) *PythonSdk {
return dag.
PythonSdk().
WithBaseImage(ref)
}
@function
def example(ref: str) -> dag.PythonSdk:
return (
dag.python_sdk()
.with_base_image(ref)
)
@func()
example(ref: string): PythonSdk {
return dag
.pythonSdk()
.withBaseImage(ref)
}
useUv() 🔗
Check whether to use uv or not
Return Type
Boolean !
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
use-uv
func (m *myModule) example(ctx context.Context) bool {
return dag.
PythonSdk().
UseUv(ctx)
}
@function
async def example() -> bool:
return await (
dag.python_sdk()
.use_uv()
)
@func()
async example(): Promise<boolean> {
return dag
.pythonSdk()
.useUv()
}
withUv() 🔗
Enable the use of uv
Return Type
PythonSdk !
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
with-uv
func (m *myModule) example() *PythonSdk {
return dag.
PythonSdk().
WithUv()
}
@function
def example() -> dag.PythonSdk:
return (
dag.python_sdk()
.with_uv()
)
@func()
example(): PythonSdk {
return dag
.pythonSdk()
.withUv()
}
withoutUv() 🔗
Disable the use of uv
Return Type
PythonSdk !
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
without-uv
func (m *myModule) example() *PythonSdk {
return dag.
PythonSdk().
WithoutUv()
}
@function
def example() -> dag.PythonSdk:
return (
dag.python_sdk()
.without_uv()
)
@func()
example(): PythonSdk {
return dag
.pythonSdk()
.withoutUv()
}
uvVersion() 🔗
Version to use for uv
Return Type
String !
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
uv-version
func (m *myModule) example(ctx context.Context) string {
return dag.
PythonSdk().
UvVersion(ctx)
}
@function
async def example() -> str:
return await (
dag.python_sdk()
.uv_version()
)
@func()
async example(): Promise<string> {
return dag
.pythonSdk()
.uvVersion()
}
withUvVersion() 🔗
Override the uv version
Needs to be called before Load. Enables uv if not already enabled.
Return Type
PythonSdk !
Arguments
Name | Type | Default Value | Description |
---|---|---|---|
version | String ! | - | The uv version |
Example
dagger -m github.com/dagger/dagger/sdk/python/runtime@4f65c2760142a5161d861cda63e4abfde7d97ec4 call \
with-uv-version --version string
func (m *myModule) example(version string) *PythonSdk {
return dag.
PythonSdk().
WithUvVersion(version)
}
@function
def example(version: str) -> dag.PythonSdk:
return (
dag.python_sdk()
.with_uv_version(version)
)
@func()
example(version: string): PythonSdk {
return dag
.pythonSdk()
.withUvVersion(version)
}