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

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 Distribution

genja_py-0.1.0.tar.gz (310.1 kB view details)

Uploaded Source

Built Distributions

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

genja_py-0.1.0-cp314-cp314-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.14Windows x86-64

genja_py-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

genja_py-0.1.0-cp314-cp314-macosx_11_0_arm64.whl (2.5 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

genja_py-0.1.0-cp313-cp313-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.13Windows x86-64

genja_py-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

genja_py-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (2.5 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

genja_py-0.1.0-cp312-cp312-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.12Windows x86-64

genja_py-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

genja_py-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (2.5 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

genja_py-0.1.0-cp311-cp311-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.11Windows x86-64

genja_py-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

genja_py-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (2.5 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

genja_py-0.1.0-cp310-cp310-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.10Windows x86-64

genja_py-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

genja_py-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (2.5 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file genja_py-0.1.0.tar.gz.

File metadata

  • Download URL: genja_py-0.1.0.tar.gz
  • Upload date:
  • Size: 310.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for genja_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 72c49562e3970a0f66678b17637f4c4972ef922aff5719d9651173bfb871aecc
MD5 4ddf2e20234889a5fae0958d05b0179e
BLAKE2b-256 7d826bd2fc9e53b1fc816bd7f0dec96c77a0fc0f9a72d62f863d85a53099c78d

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.0.tar.gz:

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.1.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: genja_py-0.1.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 2.3 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.1.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 dee97cbf024e0203d80515c745ad0ba6740111cca892a5bed4c340b6e3368f79
MD5 dbf10bfa938e25bf47a8de4892693ced
BLAKE2b-256 91f0b32929672f540529d4c8606155c34a61a8376f65b63e8f619d4b4e0b4761

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.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.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genja_py-0.1.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7207c8ccd6ab8abed815e0901553f5a634227a409de3b049a798a125a9bb9a18
MD5 b203e2d1de7dbdb6555ecd7cefbbef82
BLAKE2b-256 519463786463891314bb692822b781b188cd236e7c3627c034b01213f2e61918

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.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.1.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for genja_py-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2be52d5aa66e93f7cb4b72bdcfc68e202caeb8a6afb1dc7ad2d91d59186135f5
MD5 6a8eb07f6aa941d3a2cc91fad9bd035f
BLAKE2b-256 615e9dd260d69f0c16dda5b465877e33a1c79bc52d58d4fc5d7142c7c9b4ea49

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.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.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: genja_py-0.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.3 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.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f641c6d796d50f39ceb0cbab81d371b934e35df7fc64060945b02f05a5d2b50c
MD5 58a77d3ee48099e3dd7a5050b487628f
BLAKE2b-256 4b5f9322042128903e382d8cdba7d3cb654b4f7bf3358a8ac367addfe5c30e87

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.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.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genja_py-0.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9afe9432dc53696a2eab7ea8d38fb36e90bd06b94b90556ad1092ddf2c5df0cc
MD5 aceac5a5f96a9c375ea2f562c97aabe6
BLAKE2b-256 a8a16352349f9745e43e0f3a7b9bb690c197a9ab216af63377762a14157b4a43

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.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.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for genja_py-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 29175cb0063b6c9ca9838df1721a8437b7ae1a3a5a24d9a05ff4a0e08bac34a5
MD5 ed991808e869da3a2e49dcd3b82ff7f2
BLAKE2b-256 3401dcadf8f649191eeb514469c3ea5353e3941aa25ac64810e65d38e61e423f

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.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.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: genja_py-0.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.3 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.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 73512fe9b6b5499b52d7539a8f59eab8aeb1d7f2d4c2f129b1f3b54f0cd9575a
MD5 0463002493171d488c0ded9ee228f508
BLAKE2b-256 a4525724d02a893c07a5ecac2d3e03b6ab3d6ad777f0080ac12286f5aa183b7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.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.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genja_py-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3970c8b38891f3aeb74d78368c3ba991fdbb78fc2d97ef6ff39daeff46812806
MD5 47ab92b483227139092da1c4b4e25267
BLAKE2b-256 64ce0e0242d18d7ca8d7a4d4b34e3ff5063b36317a5e49cc846f499d70979d98

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.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.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for genja_py-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 79e587ff10b64cc7cd17ecc77ecadf7c42ea08dc9a70b49be0584efe12421254
MD5 17d242d85d463e5432225bf30efce5b7
BLAKE2b-256 06676b280082eaccd38314d4f88ea18f64e708835ba2a9e0384d9c19f8bc7f24

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.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.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: genja_py-0.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.3 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.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8d9db8df5ccb49de18e30d47e4204b3bc84335cf75249a8cad91318458b11dc9
MD5 63c1cc783422497110ca4612cf2c68af
BLAKE2b-256 3ce25acf45be13e5922d6cc2151e5b128b04ea14030749084e1089217930cdd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.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.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genja_py-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a5ac249bf13ce653d08f23dbcc76a42a5b1e49fb6a2dbe2e59af3573f4829b92
MD5 8b890825d0e71f90015b3ce1c6aee4e9
BLAKE2b-256 9ceade81ff7b04f85226eaacb1ad61e15567ec8b38f44b319445cf00a64c86ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.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.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for genja_py-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 98b91042c60326abfcc35508bd80c9d881b2e6f9d4547283df16243973e82a43
MD5 8c6423a12e3024198b209be21985ba65
BLAKE2b-256 89b839e5227538fdf855b43e930611507071fbc869675e0c9a8d8d1885f81196

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.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.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: genja_py-0.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.3 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.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9c92732135aa8ed340d47910e7f23b906f23ace0d0edda2bf59d2bb553ab7ec9
MD5 732905024baac3eb9a167d9b039dd904
BLAKE2b-256 8e94328fbe5a61d9ce290046e31350fbcbf28da49f4a91c63e15970f7e6fa408

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.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.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genja_py-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 669cc994ea8b743de9256193636708c442c6daf3b6fbc0ffbf15b999fd3717e5
MD5 2f1623cb211fa0e674ddc955b9c6a32a
BLAKE2b-256 5a91cc5837873c989e7eef2105fb0d1d322779f0e00a24a83ec9e951eac39cf8

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.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.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for genja_py-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 58ee1dd96a7e600d2c612a6e0ce31147d697d1173cece3c30ed43b218d8807d2
MD5 45e1b29284a50094e851be5844394df2
BLAKE2b-256 5a64ce1921439d9c265dc70deefab9f456218ba675a89ab95de3234fecbefaf7

See more details on using hashes here.

Provenance

The following attestation bundles were made for genja_py-0.1.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