Dagger
Search

python-sdk

Runtime module for the Python SDK

Installation

dagger install github.com/dagger/dagger/sdk/python/runtime@fea2118ab5efde3df6136581a94d982f5c436cab

Entrypoint

Return Type
PythonSdk !
Arguments
NameTypeDescription
sdkSourceDirDirectory Directory with the Python SDK source code.
Example
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
func (m *myModule) example() *Directory  {
	return dag.
			PythonSdk().
			SdksourceDir()
}
@function
def example() -> dagger.Directory:
	return (
		dag.python_sdk()
		.sdksource_dir()
	)
@func()
example(): Directory {
	return dag
		.pythonSdk()
		.sdksourceDir()
}

requiredPaths() 🔗

List of patterns to allways include when loading Python modules

Return Type
[String ! ] !
Example
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
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()
}

withoutUserConfig() 🔗

Disable the discovery of custom configuration

If it’s not necessary, it’s faster without it.

Return Type
PythonSdk !
Example
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
NameTypeDefault ValueDescription
cContainer !-No description provided
Example
func (m *myModule) example(c *Container) *PythonSdk  {
	return dag.
			PythonSdk().
			WithContainer(c)
}
@function
def example(c: dagger.Container) -> dag.PythonSdk:
	return (
		dag.python_sdk()
		.with_container(c)
	)
@func()
example(c: Container): PythonSdk {
	return dag
		.pythonSdk()
		.withContainer(c)
}

baseImage() 🔗

Image reference for the base image

Return Type
String !
Example
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()
}

withBaseImage() 🔗

Override the base image reference

Return Type
PythonSdk !
Arguments
NameTypeDefault ValueDescription
imageString !-No description provided
Example
func (m *myModule) example(image string) *PythonSdk  {
	return dag.
			PythonSdk().
			WithBaseImage(image)
}
@function
def example(image: str) -> dag.PythonSdk:
	return (
		dag.python_sdk()
		.with_base_image(image)
	)
@func()
example(image: string): PythonSdk {
	return dag
		.pythonSdk()
		.withBaseImage(image)
}

useUv() 🔗

Check whether to use uv or not

Return Type
Boolean !
Example
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
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
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()
}

codegen() 🔗

Generated code for the Python module

Return Type
GeneratedCode !
Arguments
NameTypeDefault ValueDescription
modSourceModuleSource !-No description provided
introspectionJsonFile !-No description provided
Example
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
NameTypeDefault ValueDescription
modSourceModuleSource !-No description provided
introspectionJsonFile !-No description provided
Example
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
Container !
Arguments
NameTypeDefault ValueDescription
modSourceModuleSource !-No description provided
introspectionJsonFile !-No description provided
Example
func (m *myModule) example(modSource *ModuleSource, introspectionJson *File) *Container  {
	return dag.
			PythonSdk().
			Common(modSource, introspectionJson)
}
@function
def example(mod_source: dag.ModuleSource, introspection_json: dagger.File) -> dagger.Container:
	return (
		dag.python_sdk()
		.common(mod_source, introspection_json)
	)
@func()
example(modSource: ModuleSource, introspectionJson: File): Container {
	return dag
		.pythonSdk()
		.common(modSource, introspectionJson)
}

load() 🔗

Get all the needed information from the module’s metadata and source files

Return Type
PythonSdk !
Arguments
NameTypeDefault ValueDescription
modSourceModuleSource !-No description provided
Example
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 container with the base image and installer

Workdir is set to the module’s source directory.

Return Type
PythonSdk !
Example
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 skafold a new module

The following files are added: - /runtime - pyproject.toml - requirements.lock - src/main/init.py

Return Type
PythonSdk !
Example
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 for the current API schema.

Return Type
PythonSdk !
Arguments
NameTypeDefault ValueDescription
introspectionJsonFile !-No description provided
Example
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 files and install

Return Type
PythonSdk !
Example
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()
}