Skip to main content

A lightweight runtime SDK for executing Python sparkit scripts

Project description

📦 sparkit Runtime SDK

Um runtime leve para execução de scripts Python sparkit com:

  • 🧠 Geração automática de schema
  • 🖥️ CLI profissional (flags, help, validação)
  • 🔄 Compatível com stdin/stdout (modo pipeline)
  • ⚡ Execução de funções ou classes
  • Uso de @Input / @Output / @Run decoradores

🚀 Instalação

git clone https://github.com/kelwp/sparkit
cd sparkit

Ou apenas copie a pasta sparkit para a raiz do seu projeto.


⚡ Uso rápido

🔹 Exemplo com classe

from sparkitSDK import sparkit

class SampleMonitor(NodeBase):
    ip: str
    device_id: str | None = None

    outputs_def = {
        'meta': {'type': dict[str, str]}, 
        'main': {'type': dict[str, int]}
    }

    def run(self):
        self.outputs.set_data("main", {"msg": "OK"})
        sparkit.set_stdout({"teste": 1})
        self.outputs.set_data("meta", {"status": 1})

if __name__ == "__main__":
    sparkit.run(SampleMonitor)

🔹 Executando via CLI

python script.py --ip 192.168.0.1

🔹 Saída

{
  "stdout": {
    "status": "ok",
    "ip": "192.168.0.1"
  },
  "stderr": null
}

🧠 Modos de entrada

1. Flags (CLI moderna)

python script.py --ip 123

2. JSON inline

python script.py --input '{"ip":"123"}'

3. Arquivo JSON

python script.py --input-file data.json

4. stdin (modo pipeline)

echo '{"ip":"123"}' | python script.py

👉 Ideal para integração com automações e orquestradores.


📖 Help automático

python script.py --help

Exemplo:

sparkit Script CLI

Inputs:
  --ip (string, required)

Other options:
  --input '<json>'
  --input-file <file>
  --schema
  --help

Outputs:
  status (string)
  ip (string)

🧬 Schema automático

python script.py --schema

Saída:

{
  "schema": {
    "inputs": [
      {"name": "ip", "type": "string", "required": true}
    ],
    "outputs": [
      {"name": "status", "type": "string"},
      {"name": "ip", "type": "string"}
    ]
  }
}

⚙️ Tipos suportados

Tipo Exemplo CLI Resultado
string --name John "John"
number --age 25 25
boolean --active true true
array --tags '[1,2,3]' [1,2,3]
json --data '{"a":1}' { "a":1 }

🧪 Execução com função

from runtime import sparkitRuntime

def handler(ip: str):
    return {"status": "ok", "ip": ip}

if __name__ == "__main__":
    sparkitRuntime().run(handler)

🔁 Estrutura de saída

Todo script retorna:

{
  "stdout": {...},
  "stderr": null
}

Ou em caso de erro:

{
  "stdout": null,
  "stderr": {
    "type": "ValueError",
    "message": "Missing required input: ip",
    "traceback": "..."
  }
}

🧩 Integração com sparkit

Esse runtime foi projetado para funcionar diretamente em pipelines:

  • Recebe JSON via stdin
  • Retorna JSON estruturado
  • Possui schema introspectivo

👉 Ideal para:

  • automações
  • workflows
  • agentes
  • execução remota

🏗️ Arquitetura

  • sparkitRuntime

    • parsing CLI
    • leitura de inputs
    • execução
    • geração de schema
    • tratamento de erro

🔒 Validações

  • Campos obrigatórios (required)
  • Tipagem automática
  • Erros estruturados
  • Argumentos desconhecidos são rejeitados

💡 Filosofia

Esse SDK segue 3 princípios:

  1. Zero boilerplate
  2. CLI primeiro
  3. Compatível com pipelines

🚀 Roadmap

  • Autocomplete (bash/zsh)
  • Logs coloridos
  • Plugins
  • Execução assíncrona
  • Cache de execução

🤝 Contribuição

Pull requests são bem-vindos!


📄 Licença

MIT

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

sparkit-0.0.4.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

sparkit-0.0.4-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file sparkit-0.0.4.tar.gz.

File metadata

  • Download URL: sparkit-0.0.4.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for sparkit-0.0.4.tar.gz
Algorithm Hash digest
SHA256 c0b70b7265fb3eba4ff2e4c6f0f47d80e933b141e4201f401c340c78620b8140
MD5 fc625d2858213a465004aca8f4d8b633
BLAKE2b-256 2c45efa51cd73af9aac12b03eb0e6ebe788749245a93c208b25081ecefef09ed

See more details on using hashes here.

File details

Details for the file sparkit-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: sparkit-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for sparkit-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a0cf26d8f325c6f89e16481fc14dfbea3373d5ee31decc09e360cf813e8b539a
MD5 af2d0b6035d9144c53aa613a6ba0afef
BLAKE2b-256 f03bd710b1f7635b6830773835620b547cfe60dfe02afc2f143db67855a38603

See more details on using hashes here.

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