Skip to content

Programming Interface

PyDjinni has a powerful API that can be used to control the code generation directly from Python:

from pydjinni import API

API().configure("pydjinni.yaml").parse("test.djinni").generate("cpp").generate("java").write_processed_files()

is equivalent to running the CLI command:

pydjinni generate test.djinni cpp java

configuration_model property

The configuration model is assembled dynamically depending on the loaded plugins.

Returns:

Type Description
type[BaseModel]

the pydantic model that defines the required configuration structure.

external_type_model property

The type model is assembled dynamically depending on the loaded plugins.

Returns:

Type Description
type[BaseExternalType]

The pydantic model that defines the required datastructure for external types.

generation_targets cached property

Caution

The returned Target types are not considered part of the stable public API. Internals may change with any release.

Returns: dictionary of all available generator targets.

internal_types cached property

Returns:

Type Description
list

A list of all pre-defined types that are available to use in the IDL.

processed_files_model property

The model for the processed files output is assembled dynamically depending on the loaded plugins.

Returns:

Type Description
type[ProcessedFiles]

The pydantic model that defines the datastructure that will be generated by PyDjinni.

ConfiguredContext

config property

Returns:

Type Description
BaseModel

The configuration model instance that is used for further processing

GenerateContext

generate(target_name, clean=False)

generate output for a specified target based on the previously parsed IDL. Args: target_name: name (key) of the target. clean: if set to True, all output directories are purged before generating output, to make sure that no leftovers from previous executions are still present.

Returns:

Type Description
GenerateContext

the same context. Generation commands can be chained.

write_processed_files()

write the file that lists all generated files to the path specified in the configuration. If no path is configured, this does nothing. Returns: Path to the written file.

PackageContext

build(target, architectures=None, clean=False)

Build the library for a given platform target.

Parameters:

Name Type Description Default
target str

the platform that the library should be built for. Must be supported by the package plugin

required
architectures set[Architecture]

list of architectures that the library should be compiled for. Overrides the architectures defined in the configuration.

None
clean bool

If True, a clean build is preformed, meaning that the build directory is deleted and the build is started from scratch.

False

Returns: the current context.

write_package(clean=False)

combines all binaries previously built with build() into a package artifact.

Parameters:

Name Type Description Default
clean bool

if True, the packaging is done from scratch, deleting the package source directory and building it from scratch.

False

Returns: Path to the final package that has been created

package(target, configuration=None)

configure a context for package configuration

Returns:

Name Type Description
PackageContext PackageContext

the packaging context

parse(idl)

Parses the given IDL into an Abstract Syntax tree. Does not generate any file output. Args: idl: Path to the IDL file that should be processed.

Returns:

Type Description
GenerateContext

context that can be used to generate output

Raises: FileNotFoundException : When the given idl file does not exist. IdlParser.ParsingException : When the input could not be parsed. IdlParser.TypeResolvingException : When a referenced type cannot be found. IdlParser.DuplicateTypeException : When a type is re-declared. IdlParser.MarshalException : When an error happened during marshalling.

publish(target, configuration=None)

Publish a previously packaged artifact to an online repository. Depending on the type of package, the repository might vary. This command aims to provide a top-level API to publishing packages no matter what the underlying technology is.

Parameters:

Name Type Description Default
target str

the package type that should be published

required
configuration str

the configuration that should be used

None

Raises: UnknownTargetException if the given target is not known to the system

configure(path=None, options=None)

Parses the configuration input.

Parameters:

Name Type Description Default
path Path | str | None

the path to a configuration file.

None
options dict | None

a dict with additional configuration parameters.

None

Returns:

Type Description
ConfiguredContext

configured API context

Raises:

Type Description
ConfigurationException

if parsing the configuration has failed