Dagger
Search

python-sdk

Runtime module for the Python SDK

Installation

dagger install github.com/crjm/dagger/sdk/python/runtime@6c5e7b42b9e819f1ef114694149e10f362236479

Entrypoint

Return Type
PythonSdk !
Arguments
NameTypeDefault ValueDescription
sdkSourceDirDirectory -Directory with the Python SDK source code.
Example
func (m *myModule) 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()
}

container() đź”—

Resulting container after each composing step

Return Type
Container !
Example
func (m *myModule) example() *Container  {
	return dag.
			PythonSdk().
			Container()
}

modName() đź”—

The original module’s name

Return Type
String !
Example
func (m *myModule) example(ctx context.Context) string  {
	return dag.
			PythonSdk().
			ModName(ctx)
}

projectName() đź”—

The normalized python distribution package name (in pyproject.toml)

Return Type
String !
Example
func (m *myModule) example(ctx context.Context) string  {
	return dag.
			PythonSdk().
			ProjectName(ctx)
}

packageName() đź”—

The normalized python import package name (in the filesystem)

Return Type
String !
Example
func (m *myModule) example(ctx context.Context) string  {
	return dag.
			PythonSdk().
			PackageName(ctx)
}

mainObjectName() đź”—

The normalized main object name in Python

Return Type
String !
Example
func (m *myModule) example(ctx context.Context) string  {
	return dag.
			PythonSdk().
			MainObjectName(ctx)
}

modSource() đź”—

The source needed to load and run a module

Return Type
ModuleSource !
Example
func (m *myModule) example() *ModuleSource  {
	return dag.
			PythonSdk().
			ModSource()
}

contextDir() đź”—

ContextDir is a copy of the context directory from the module source

We add files to this directory, always joining paths with the source’s subpath. We could use modSource.Directory(“”) for that if it was read-only, but since we have to mount the context directory in the end, rather than mounting the context dir and then mounting the forked source dir on top, we fork the context dir instead so there’s only one mount in the end.

Return Type
Directory !
Example
func (m *myModule) example() *Directory  {
	return dag.
			PythonSdk().
			ContextDir()
}

contextDirPath() đź”—

ContextDirPath is a unique host path for the module being loaded

HACK: this property is computed as a unique value for a ModuleSource to provide a unique path on the filesystem. This is because the uv cache uses hashes of source paths - so we need to have something unique, or we can get very real conflicts in the uv cache.

Return Type
String !
Example
func (m *myModule) example(ctx context.Context) string  {
	return dag.
			PythonSdk().
			ContextDirPath(ctx)
}

subPath() đź”—

Relative path from the context directory to the source directory

Return Type
String !
Example
func (m *myModule) example(ctx context.Context) string  {
	return dag.
			PythonSdk().
			SubPath(ctx)
}

isInit() đź”—

True if the module is new and we need to create files from the template

It’s assumed that this is the case if there’s no pyproject.toml file.

Return Type
Boolean !
Example
func (m *myModule) example(ctx context.Context) bool  {
	return dag.
			PythonSdk().
			IsInit(ctx)
}

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()
}

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
ctrContainer !-The container to use
Example
func (m *myModule) example(ctr *Container) *PythonSdk  {
	return dag.
			PythonSdk().
			WithContainer(ctr)
}

baseImage() đź”—

Image reference for the base container

Return Type
String !
Example
func (m *myModule) example(ctx context.Context) string  {
	return dag.
			PythonSdk().
			BaseImage(ctx)
}

uvImage() đź”—

Image reference where uv is fetched from

Return Type
String !
Example
func (m *myModule) example(ctx context.Context) string  {
	return dag.
			PythonSdk().
			UvImage(ctx)
}

withBaseImage() đź”—

Override the base container’s image

Needs to be called before Load.

Return Type
PythonSdk !
Arguments
NameTypeDefault ValueDescription
refString !-The image reference
Example
func (m *myModule) example(ref string) *PythonSdk  {
	return dag.
			PythonSdk().
			WithBaseImage(ref)
}

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)
}

withUv() đź”—

Enable the use of uv

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

uvVersion() đź”—

Version to use for uv

Return Type
String !
Example
func (m *myModule) example(ctx context.Context) string  {
	return dag.
			PythonSdk().
			UvVersion(ctx)
}

indexUrl() đź”—

Uv’s default index URL setting

Return Type
String !
Example
func (m *myModule) example(ctx context.Context) string  {
	return dag.
			PythonSdk().
			IndexUrl(ctx)
}

extraIndexUrl() đź”—

Uv’s “extra-index-url” setting

Return Type
String !
Example
func (m *myModule) example(ctx context.Context) string  {
	return dag.
			PythonSdk().
			ExtraIndexUrl(ctx)
}

withUvVersion() đź”—

Override the uv version

Needs to be called before Load. Enables uv if not already enabled.

Return Type
PythonSdk !
Arguments
NameTypeDefault ValueDescription
versionString !-The uv version
Example
func (m *myModule) example(version string) *PythonSdk  {
	return dag.
			PythonSdk().
			WithUvVersion(version)
}

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)
}

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)
}

common() đź”—

Common steps for the ModuleRuntime and Codegen functions

Return Type
PythonSdk !
Arguments
NameTypeDefault ValueDescription
modSourceModuleSource !-No description provided
introspectionJsonFile !-No description provided
Example
func (m *myModule) 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
NameTypeDefault ValueDescription
modSourceModuleSource !-No description provided
Example
func (m *myModule) 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
func (m *myModule) example() *PythonSdk  {
	return dag.
			PythonSdk().
			WithBase()
}

withTemplate() đź”—

Add the template files to skaffold a new module

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

Return Type
PythonSdk !
Example
func (m *myModule) 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
NameTypeDefault ValueDescription
introspectionJsonFile !-No description provided
Example
func (m *myModule) example(introspectionJson *File) *PythonSdk  {
	return dag.
			PythonSdk().
			WithSdk(introspectionJson)
}

withSource() đź”—

Add the module’s source code

Return Type
PythonSdk !
Example
func (m *myModule) example() *PythonSdk  {
	return dag.
			PythonSdk().
			WithSource()
}

withUpdates() đź”—

Make any updates to current source

Return Type
PythonSdk !
Example
func (m *myModule) example() *PythonSdk  {
	return dag.
			PythonSdk().
			WithUpdates()
}

withInstall() đź”—

Install the module’s package and dependencies

Return Type
PythonSdk !
Example
func (m *myModule) example() *PythonSdk  {
	return dag.
			PythonSdk().
			WithInstall()
}

addNewFile() đź”—

AddNewFile adds a new file, with contents, to the module’s source.

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
nameString !-No description provided
contentsString !-No description provided
Example
func (m *myModule) example(ctx context.Context, name string, contents string)   {
	return dag.
			PythonSdk().
			AddNewFile(ctx, name, contents)
}

addFile() đź”—

AddFile adds a file to the module’s source.

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
nameString !-No description provided
fileFile !-No description provided
Example
func (m *myModule) example(ctx context.Context, name string, file *File)   {
	return dag.
			PythonSdk().
			AddFile(ctx, name, file)
}

getFile() đź”—

GetFile returns a file from the module’s source.

Return Type
File !
Arguments
NameTypeDefault ValueDescription
nameString !-No description provided
Example
func (m *myModule) example(name string) *File  {
	return dag.
			PythonSdk().
			GetFile(name)
}

useUvLock() đź”—

UseUvLock returns true if the runtime should expect a uv.lock file.

Return Type
Boolean !
Example
func (m *myModule) example(ctx context.Context) bool  {
	return dag.
			PythonSdk().
			UseUvLock(ctx)
}

addDirectory() đź”—

AddDirectory adds a directory to the module’s source.

Return Type
Void !
Arguments
NameTypeDefault ValueDescription
nameString !-No description provided
dirDirectory !-No description provided
Example
func (m *myModule) example(ctx context.Context, name string, dir *Directory)   {
	return dag.
			PythonSdk().
			AddDirectory(ctx, name, dir)
}

source() đź”—

We could use modSource.Directory(“”) but we’ll need to use the context directory in GeneratedCode later, so rather than trying to replace the source directory in the context directory, we’ll just use the context directory with subpath everywhere.

Return Type
Directory !
Example
func (m *myModule) example() *Directory  {
	return dag.
			PythonSdk().
			Source()
}