Dagger
Search

python-sdk

Runtime module for the Python SDK

Installation

dagger install github.com/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5

Entrypoint

Return Type
PythonSdk !
Arguments
NameTypeDefault ValueDescription
sdkSourceDirDirectory -Directory with the Python SDK source code.
Example
dagger -m github.com/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5 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/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5 call \
 sdksource-dir
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
dagger -m github.com/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5 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/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5 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()
}

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/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5 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
NameTypeDefault ValueDescription
cContainer !-No description provided
Example
dagger -m github.com/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5 call \
 with-container --c IMAGE:TAG
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
dagger -m github.com/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5 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()
}

withBaseImage() 🔗

Override the base image reference

Return Type
PythonSdk !
Arguments
NameTypeDefault ValueDescription
imageString !-No description provided
Example
dagger -m github.com/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5 call \
 with-base-image --image string
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
dagger -m github.com/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5 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/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5 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/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5 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()
}

codegen() 🔗

Generated code for the Python module

Return Type
GeneratedCode !
Arguments
NameTypeDefault ValueDescription
modSourceModuleSource !-No description provided
introspectionJsonString !-No description provided
Example
echo 'Custom types are not supported in shell examples'
func (m *myModule) example(modSource *ModuleSource, introspectionJson string) *GeneratedCode  {
	return dag.
			PythonSdk().
			Codegen(modSource, introspectionJson)
}
@function
def example(mod_source: dag.ModuleSource, introspection_json: str) -> dag.GeneratedCode:
	return (
		dag.python_sdk()
		.codegen(mod_source, introspection_json)
	)
@func()
example(modSource: ModuleSource, introspectionJson: string): 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
introspectionJsonString !-No description provided
Example
echo 'Custom types are not supported in shell examples'
func (m *myModule) example(modSource *ModuleSource, introspectionJson string) *Container  {
	return dag.
			PythonSdk().
			ModuleRuntime(modSource, introspectionJson)
}
@function
def example(mod_source: dag.ModuleSource, introspection_json: str) -> dagger.Container:
	return (
		dag.python_sdk()
		.module_runtime(mod_source, introspection_json)
	)
@func()
example(modSource: ModuleSource, introspectionJson: string): 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
introspectionJsonString !-No description provided
Example
echo 'Custom types are not supported in shell examples'
func (m *myModule) example(modSource *ModuleSource, introspectionJson string) *Container  {
	return dag.
			PythonSdk().
			Common(modSource, introspectionJson)
}
@function
def example(mod_source: dag.ModuleSource, introspection_json: str) -> dagger.Container:
	return (
		dag.python_sdk()
		.common(mod_source, introspection_json)
	)
@func()
example(modSource: ModuleSource, introspectionJson: string): 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
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 container with the base image and installer

Workdir is set to the module’s source directory.

Return Type
PythonSdk !
Example
dagger -m github.com/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5 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 skafold 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/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5 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 for the current API schema.

Return Type
PythonSdk !
Arguments
NameTypeDefault ValueDescription
introspectionJsonString !-No description provided
Example
dagger -m github.com/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5 call \
 with-sdk --introspection-json string
func (m *myModule) example(introspectionJson string) *PythonSdk  {
	return dag.
			PythonSdk().
			WithSdk(introspectionJson)
}
@function
def example(introspection_json: str) -> dag.PythonSdk:
	return (
		dag.python_sdk()
		.with_sdk(introspection_json)
	)
@func()
example(introspectionJson: string): PythonSdk {
	return dag
		.pythonSdk()
		.withSdk(introspectionJson)
}

withSource() 🔗

Add the module’s source files and install

Return Type
PythonSdk !
Example
dagger -m github.com/samalba/dagger/sdk/python/runtime@fa43f9a82f24b1aca922340c5801ad728e05d1e5 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()
}