Skip to main content

SDK de Python para la plataforma NEZ (Networking Execution Zone)

Project description

NEZ Python SDK

Python License

SDK profesional en Python para interactuar con la plataforma NEZ.

Este proyecto no es un wrapper simple. Su objetivo es abstraer un backend legacy e inconsistente, traduciendo errores, estabilizando payloads y ofreciendo una API de uso clara para el desarrollador.

Que resuelve

  • Uso de access_token como query param en todos los requests.
  • Traduccion de errores del backend a excepciones Python mas claras.
  • Soporte para workflows manuales y workflows definidos por DSL.
  • Reautenticacion automatica opcional contra el backend NEZ.
  • Pruebas unitarias con pytest y script integral de validacion.

Requisitos

  • Python 3.10 o superior
  • Instancia activa de NEZ
  • Token valido o credenciales validas para autoauth

Instalacion

pip install -e ".[dev]"

Estructura

nez_sdk/
├── auto_auth.py
├── exceptions.py
├── http_client.py
├── nez.py
├── models/
├── services/
└── utils/
tests/
test_nez_sdk.py
configuration.cfg

Inicio rapido con token

from nez_sdk.nez import Nez

nez = Nez(
    base_url="http://localhost:20510/api/v1",
    token="tu_access_token"
)

nfrs = nez.nfrs.list()
print("NFRs disponibles:", len(nfrs))

Inicio rapido con autoautenticacion

from nez_sdk.nez import Nez

nez = Nez(base_url="http://localhost:20510/api/v1")

token = nez.authenticate(
    user="tu_usuario_o_email",
    password="tu_password",
    use_gateway=False
)

print("Token obtenido:", token)

La autoautenticacion usa estos endpoints del backend NEZ:

  • POST /auth/api.php?type=6
  • POST /APIGateway/API.php?type=20

Modelos principales

Los modelos actuales viven en:

  • nez_sdk.models.model_building_block.BuildingBlock
  • nez_sdk.models.model_stage.Stage
  • nez_sdk.models.model_workflow.Workflow
  • nez_sdk.models.model_nfr.NFR

Building Blocks

Crear

from nez_sdk.models.model_building_block import BuildingBlock

bb = BuildingBlock(
    name="thumbnail-service",
    image="registry.example.com/thumbnail:1.0",
    command="python app.py",
    description="Procesa imagenes",
    port=8080
)

response = nez.buildingblocks.create(bb)
print(response)

Listar

buildingblocks = nez.buildingblocks.list()

for item in buildingblocks:
    print(item.id, item.name, item.image)

Actualizar y eliminar

nez.buildingblocks.update("1", bb)
nez.buildingblocks.delete("1")

Nota: los endpoints existen y el SDK los ejecuta, pero el backend NEZ puede responder con 405 u otros errores segun la instancia.

Workflows

Crear workflow manual

from nez_sdk.models.model_stage import Stage
from nez_sdk.models.model_workflow import Workflow

stage = Stage("stage-procesamiento", [bb])
workflow = Workflow("workflow-demo", [stage])

workflow_id = nez.build(workflow)
print(workflow_id)

Endpoints disponibles

nez.workflows.list()
nez.workflows.get("1")
nez.workflows.update("1", workflow)
nez.workflows.delete("1")
nez.workflows.stages("1")

Workflows usando DSL

Puedes definir workflows en configuration.cfg y convertirlos a objetos Python con DSLParser.

Ejemplo

from nez_sdk.utils.dsl_parser import DSLParser

workflow = DSLParser.from_file("configuration.cfg")

print(workflow.name)
print(len(workflow.stages))

workflow_id = nez.build(workflow)
print(workflow_id)

Ejecucion

nez.execution.run("1", platform="docker")
nez.execution.execute("1", puzzle_name="default")
nez.execution.stop("1", puzzle_name="default")
nez.execution.log("1", name="default", folder="/tmp")

Tambien existe la fachada:

nez.execute("1")

Manejo de errores

Excepciones principales:

  • NezAPIError
  • NezAuthError
  • NezNotFoundError
  • NezValidationError
  • NezConnectionError
  • NezResponseError

Ejemplo:

from nez_sdk.exceptions import NezAPIError

try:
    nez.workflows.update("1", workflow)
except NezAPIError as exc:
    print(exc)

Testing

Pruebas unitarias

pytest -q

Script integral/manual

python test_nez_sdk.py

El script test_nez_sdk.py muestra:

  • modelos
  • DSL
  • autoauth
  • NFRs
  • building blocks
  • workflows
  • execution
  • errores esperados

Demo

Puedes ejecutar el demo de uso general:

python demo_nez_sdk.py

Variables de entorno soportadas por demo_nez_sdk.py y test_nez_sdk.py:

  • NEZ_BASE_URL
  • NEZ_TOKEN
  • NEZ_AUTH_USER
  • NEZ_AUTH_PASSWORD
  • NEZ_AUTH_USE_GATEWAY

Puedes partir de .env.example para configurar tu entorno local.

Documentacion

La documentacion del proyecto usa MkDocs + mkdocstrings.

Instalacion:

pip install -e ".[docs]"

Vista previa local:

mkdocs serve

Build:

mkdocs build --strict

El proyecto incluye un workflow de GitHub Actions para:

  • validar y construir la documentacion en feature/sdk-refactor
  • desplegar la documentacion en GitHub Pages desde main o mediante ejecucion manual

Releases y publicacion

El proyecto incluye un workflow de GitHub Actions para:

  • construir el paquete Python
  • crear automaticamente un Release en GitHub
  • publicar automaticamente en PyPI cuando se cree un tag de version

Flujo esperado:

git tag v1.0.1
git push origin v1.0.1

La publicacion en PyPI esta preparada para funcionar con Trusted Publishing usando la accion oficial pypa/gh-action-pypi-publish.

Estado actual

Este SDK ya cubre:

  • endpoints documentados del PDF
  • autoautenticacion
  • traduccion robusta de errores
  • pruebas unitarias con alta cobertura

La principal fuente de inestabilidad sigue siendo el backend NEZ, no la estructura base del SDK.

Autor

Desarrollado por Ricardo Prieto Ortega
Correo: prieto.ortega.20035@itsmante.edu.mx
GitHub: https://github.com/RicardoPrietoOrtega
LinkedIn: https://www.linkedin.com/in/ricardo-prieto-ortega/
Institucion: Instituto Tecnologico Superior de El Mante (TEC MANTE)

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

nez_sdk-1.0.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

nez_sdk-1.0.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file nez_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: nez_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nez_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 593d83fe3f75bef9c50e737b104353e5004454a6597946a907db0cbdd234c8b2
MD5 a7fc9dd023a01146a52ad34f3d22effe
BLAKE2b-256 94679ccdd9dd0311422c938a10ec5fc7871004264bb13871609e9f1ecb21c3cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for nez_sdk-1.0.0.tar.gz:

Publisher: publish.yml on jub-ecosystem/nez-sdk

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

File details

Details for the file nez_sdk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: nez_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nez_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 89792e022203a4017428a97076ede4cce7f74aa8b4c7c1516fb9c7f4dd0f466a
MD5 cf49c8dc18e17725ced2717dc2647a39
BLAKE2b-256 2cf353b9600bee130caa8719f517216efad48d6211b69fc2ea7741b69d8d368f

See more details on using hashes here.

Provenance

The following attestation bundles were made for nez_sdk-1.0.0-py3-none-any.whl:

Publisher: publish.yml on jub-ecosystem/nez-sdk

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