Skip to main content

Python bindings for the Genja runtime

Project description

genja-py

Python bindings for the Genja runtime.

This package exposes the genja module, which wraps the Rust runtime and lets Python code:

  • build a runtime from hosts, a full inventory, or a settings file
  • run Python-authored tasks
  • register Python plugins
  • inspect raw and transformed inventory data

Installation

For end users, install the package with pip:

pip install genja-py

The package currently exposes the genja Python module:

import genja

Quick Start

Create a runtime from a simple host mapping:

import genja
from genja.task import Host, TaskInfo, TaskRuntimeContext, TaskSuccessResult, task


@task(name="backup_config")
class BackupTask:
    def start(
        self,
        task: TaskInfo,
        host: Host,
        context: TaskRuntimeContext,
    ) -> TaskSuccessResult:
        connection = context.connection()
        command_output = None
        if connection is not None:
            command_output = connection.execute_command("show running-config")

        return TaskSuccessResult(
            summary=f"backed up {host.hostname}",
            metadata={"show_running_config": command_output},
        )


genja = genja.Genja.from_hosts(
    {
        "router1": {"hostname": "10.0.0.1", "platform": "ios"},
        "router2": {"hostname": "10.0.0.2", "platform": "nxos"},
    }
).with_runner("serial")

results = genja.run_task(BackupTask)
print(results.to_dict())

tasks = genja.Tasks()
tasks.add_task(BackupTask)

all_results = genja.run_tasks(tasks)
print([result.task_name for result in all_results])

results.to_dict() returns per-host task results with an outcome payload and separate execution_metadata for host timing and retry attempt information.

TaskRuntimeContext exposes the resolved connection through context.connection() and context.has_connection(). Execution depth remains internal to the runtime.

For async Python applications, use the async entrypoints:

import asyncio
import genja
from genja.task import Host, TaskInfo, TaskRuntimeContext, TaskSuccessResult, task


@task(name="backup_config_async")
class BackupTaskAsync:
    async def start_async(
        self,
        task: TaskInfo,
        host: Host,
        context: TaskRuntimeContext,
    ) -> TaskSuccessResult:
        connection = context.connection()
        command_output = None
        if connection is not None:
            command_output = await connection.execute_command("show running-config")

        return TaskSuccessResult(
            summary=f"backed up {host.hostname}",
            metadata={"show_running_config": command_output},
        )


async def main() -> None:
    runtime = genja.Genja.from_hosts(
        {
            "router1": {"hostname": "10.0.0.1", "platform": "ios"},
        }
    ).with_runner("serial")

    results = await runtime.run_task_async(BackupTaskAsync)
    print(results.to_dict())


asyncio.run(main())

Use run_task_async(...) and run_tasks_async(...) when composing Genja with asyncio.gather(...) or other async application code. The synchronous run_task(...) and run_tasks(...) entrypoints remain available for scripts and non-async callers.

Python task authoring rules:

  • Define def start(...) for blocking tasks.
  • Define async def start_async(...) for async tasks.
  • Define exactly one of those methods on a @task(...) class.
  • Use sub_tasks=[ChildTask, ...] to declare child tasks.

Full Inventory

Use genja.inventory when you need groups and defaults:

import genja
from genja.inventory import Defaults, Group, Host, Inventory

inventory = Inventory(
    hosts={
        "router1": Host(hostname="10.0.0.1", groups=["core"]),
    },
    groups={
        "core": Group(platform="ios", data={"role": "core"}),
    },
    defaults=Defaults(username="admin", port=22),
)

genja = genja.Genja.from_inventory(inventory)

print(genja.inventory_full())
print(genja.inventory_raw())

Inventory Accessors

The runtime exposes three inventory views:

  • genja.inventory(): raw hosts only
  • genja.inventory_full(): transformed hosts, groups, and defaults
  • genja.inventory_raw(): raw hosts, groups, and defaults

Plugins

You can register Python plugins directly:

import genja


class MyProcessorPlugin:
    name = "audit"
    group = "ProcessorPlugin"

    def on_task_finish(self, context, results):
        return None


plugins = genja.PluginManager()
plugins.register_plugin(MyProcessorPlugin())

Rust plugins can be loaded from a directory:

plugins = genja.PluginManager()
plugins.load_rust_plugins_from_directory("./plugins")

Settings Files

Build a runtime from a settings file:

import genja

genja = genja.Genja.from_settings_file("config.yaml")

If you need Python plugins during settings-file loading, provide a plugin manager:

plugins = genja.PluginManager()
genja = genja.Genja.from_settings_file("config.yaml", plugin_manager=plugins)

Development

The commands below assume a repository checkout and use PDM-managed tooling.

Clone the repository and move into the Python package directory:

git clone git@github.com:Smertan/genja.git
cd genja/genja-core-python

Install the development dependencies:

pdm install -d

Build and install the Rust extension into the project virtual environment:

pdm run maturin develop

Run the Rust-side binding tests:

pdm run test-rust

Use pdm run test-rust instead of plain cargo test. The Rust tests embed Python and need access to the PDM-managed virtualenv packages such as pydantic.

Run the Python test suite:

pdm run test

Run Ruff:

pdm run lint

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

genja_py-0.2.0-cp314-cp314-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.14Windows x86-64

genja_py-0.2.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

genja_py-0.2.0-cp314-cp314-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

genja_py-0.2.0-cp313-cp313-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.13Windows x86-64

genja_py-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

genja_py-0.2.0-cp313-cp313-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

genja_py-0.2.0-cp312-cp312-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.12Windows x86-64

genja_py-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

genja_py-0.2.0-cp312-cp312-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

genja_py-0.2.0-cp311-cp311-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.11Windows x86-64

genja_py-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

genja_py-0.2.0-cp311-cp311-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

genja_py-0.2.0-cp310-cp310-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.10Windows x86-64

genja_py-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

genja_py-0.2.0-cp310-cp310-macosx_11_0_arm64.whl (2.6 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file genja_py-0.2.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: genja_py-0.2.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for genja_py-0.2.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 bdd8f6812f00bd0c265c4e4e4de4a8eb77f917dc4e5bf114c5cdc1ecaa37b4a1
MD5 d9ddcd7ef73d1907e54317873561ba54
BLAKE2b-256 8e82eb9b70f6be8a85a919ddb69ec43b84c2211ba4a639c154eafea2676bde37

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.2.0-cp314-cp314-win_amd64.whl:

Publisher: publish-python.yml on Smertan/genja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genja_py-0.2.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genja_py-0.2.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9ef28fb44de370f138de94ffddcd2ffa6fa9214ceb91b927696b4c9b7b1c4d6b
MD5 14be10a0d9f674cb260d770946c17b43
BLAKE2b-256 3efa039910868272e9c4dff7532a9d1dc05d4596e833e4c40b541f8551dc85a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.2.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-python.yml on Smertan/genja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genja_py-0.2.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for genja_py-0.2.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 58ea170f40cced46a3ebafbfe621704a79423654138d3721e959305ee0b914dd
MD5 5e2c10dc1964e7ff3d6106f44e2911d4
BLAKE2b-256 b8f833e9c0ef7e0ffcd255743e2f44bbf4ee6a1b2127e59b015dae965922f8b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.2.0-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: publish-python.yml on Smertan/genja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genja_py-0.2.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: genja_py-0.2.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for genja_py-0.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4f59b96f4431b02c690c9a85908f14d7c691dda2508989e05b517ef9d1786f4c
MD5 9468e04e2132c69893c58c938dc404ae
BLAKE2b-256 5aa0946e6b05598b0ee0eecb15c8dbcfd566ac986997e4afd83e8fdf32046e0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.2.0-cp313-cp313-win_amd64.whl:

Publisher: publish-python.yml on Smertan/genja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genja_py-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genja_py-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 57a55837a26941d5ec2c5bfdf6383e7b3df30434cc0adc3190b9f66eb1522b07
MD5 05320561ab87fa1f672dae64788febc5
BLAKE2b-256 e573f57c4ad7f257b1d6d34b7b38e71d4c504296d5a4ae8612c870e4496d5991

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-python.yml on Smertan/genja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genja_py-0.2.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for genja_py-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dee2027c3b9670920aba9e88756a4e9eae92b9ff39860ed0b395d0441fd998e2
MD5 b00e57d546c461c2a1f4d07182225193
BLAKE2b-256 250c5411fd45a1c064a109df879bee2b54375ecfe70ea42863d4687319c503da

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.2.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish-python.yml on Smertan/genja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genja_py-0.2.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: genja_py-0.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for genja_py-0.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 42725824b2f28887fd0020a1ee67207bd9b50cc401e3f0efdcd1ac1d589683a3
MD5 154b902832f0be02eff39625e8602a01
BLAKE2b-256 3413ec455394e029e3df61a34a621f4bfd974f639e6b392978e0b0fee2c4db88

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.2.0-cp312-cp312-win_amd64.whl:

Publisher: publish-python.yml on Smertan/genja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genja_py-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genja_py-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc358db2451ab7709b2d196f8e0088e20997cb0eff96ce0705753ad98094e748
MD5 b6d20a5687793899787064550d1e77cd
BLAKE2b-256 5b0d74ebf03cee8d6ba928feeec4686f5a9374e479a1a60c48ef65259181fc54

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-python.yml on Smertan/genja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genja_py-0.2.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for genja_py-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9649627b849794f914610340fda3bb78fb10e885aef41ee8a5dfb53d30c132c2
MD5 49302edd7a7c8ebdae3ffb99be70a2f2
BLAKE2b-256 d8d01755d344e7bba582a730586e03652e5f3d0f41edd138ef01345cc4f99c6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.2.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish-python.yml on Smertan/genja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genja_py-0.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: genja_py-0.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for genja_py-0.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 018ebec763bd11bffe41e456296b0b752b846972de11d8030040842c171ec210
MD5 71eb80f56bae3344a1b6d9f546c8ec38
BLAKE2b-256 b6647e12e7cef2f46a23044f99ba0ff919ed2c6a6d6cf805b0f86f67c7641099

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.2.0-cp311-cp311-win_amd64.whl:

Publisher: publish-python.yml on Smertan/genja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genja_py-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genja_py-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fc1a692de38117c21e1dad640eef0242b6b77913675a5d92157e195748f15ce6
MD5 e4bef636a99853e0503257a3d505b8e1
BLAKE2b-256 0386c23990e81e7ada43c915de395f5aec726242a7cf313a84ecf73efb8aaeb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-python.yml on Smertan/genja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genja_py-0.2.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for genja_py-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f7cd95198e384abc7962883f0fb37160b5a5309648a18566f77e8e5f7c321882
MD5 26e7fc039410f068491835e4326b1da2
BLAKE2b-256 41e7e07a3f8f341e568c8b8572400369a26698ac299088c603cfbd5be508d71d

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.2.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish-python.yml on Smertan/genja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genja_py-0.2.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: genja_py-0.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for genja_py-0.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 31a728aff8c4e178433ed05816ea8477ce352d0d86f331e59ed1a2d723344bb3
MD5 9b990e30479a24ea71987bcfb3d30574
BLAKE2b-256 0b0a9d63d5bda24816025d9139e845efebfd2a3e92a548b92180996c531e7d69

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.2.0-cp310-cp310-win_amd64.whl:

Publisher: publish-python.yml on Smertan/genja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genja_py-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genja_py-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1519db33edbd504be17fb205bfad9446f8de8ebdc6b94f200839f4b1178db637
MD5 a2e4f58938cd2f07ae85784a1de6d134
BLAKE2b-256 1d2778fca390606fe0a07fe42b21a54ac00c69715ad0827387c92c36b4e878e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-python.yml on Smertan/genja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file genja_py-0.2.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for genja_py-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 691eab554d9e49f45326da2c23497bed1d17156add0eec9a4464639c00bb57bf
MD5 b26d3e99b80545b3ce8e2b55148a7a5c
BLAKE2b-256 b4545a5b1ad8676329751089b55648f7ae09f821286501199a7e539019323757

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.2.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: publish-python.yml on Smertan/genja

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page