Skip to main content

NWeb Client

Client to access the NWeb-API

Installation

pip install --upgrade nwebclient

# oder

pip install .

python -m nwebclient help

More Documentation

Docker

docker run --rm -it -p 7171:7070 -e PIP_PKGS=/parent/home/pi/dev/nxbot -v /:/parent/ nxware/nxdev npy serv --install

Beispiel

import nwebclient
class NWebClient
  """ Anstatt url kann auch ein Pfad zur einer JSON-Datei, die die Schluessel enthaelt, angegeben werden. """
  __init__(url, username,password)
  doc(id)
  docs(q)
  group(id)
  getOrCreateGroup(guid, title)
  downloadImages()

metric_val(endpointUrl:string, metricName:string, val:numeric)

Runner per stdin/stdout (--stdio)

Neben --rest und --mqtt kann der Runner Jobs über stdin entgegennehmen (JSON Lines). Jede Zeile auf stdin ist ein Job (ein JSON-Objekt), für jede Zeile wird sofort eine Ergebniszeile auf stdout geschrieben. Der Runner läuft, bis stdin geschlossen wird:

printf '{"type":"echo","a":1}\n{"b":2}\n' | python -m nwebclient.runner --executor nwebclient.runner:Echo --stdio
# {"type": "echo", "a": 1, "job_type": "echo"}
# {"b": 2}

Hinweise:

  • Ein Job muss in einer Zeile stehen, mehrzeiliges (pretty-printed) JSON wird nicht unterstützt. Leere Zeilen werden ignoriert.
  • Die Antworten kommen in derselben Reihenfolge wie die Jobs. Der Runner kann so auch als langlebiger Subprozess genutzt werden (Job schreiben, Antwortzeile lesen).
  • Enthält eine Zeile ein jobs-Array, werden alle Jobs darin ausgeführt (wie bei --in), Ergebnis: {"jobs": [...]}.
  • JSON-RPC-Jobs ("jsonrpc": "2.0") werden wie beim REST-Endpoint umgeschrieben und beantwortet.
  • stdout enthält nur das Ergebnis. Alle anderen Ausgaben des Runners gehen auf stderr.
  • Bei ungültigem JSON oder einer Exception wird für diese Zeile ein Fehlerobjekt (success: false, error_message, trace) ausgegeben, die folgenden Jobs laufen weiter.
  • --stdio hat Vorrang vor --rest und --mqtt.

Secure Web Interface

Das Webinterface des Runners (--rest) kann per HTTP Basic Auth mit einem Passwort geschützt werden. Die Einstellungen werden in der Config gesetzt, z.B. in /etc/nweb.yml oder einer Datei in /etc/nx.d/:

web_secured: true
web_user: admin            # optional, Default: admin
web_password_hash: "scrypt:32768:8:1$..."

Passwort-Hash erzeugen:

python -c "from werkzeug.security import generate_password_hash as g; print(g('geheim'))"

Hinweise:

  • Ohne web_secured (oder mit false) bleibt das Webinterface offen.
  • Ist web_secured gesetzt, aber kein web_password_hash vorhanden, wird jeder Zugriff abgelehnt.
  • Ohne Passwort erreichbar bleibt nur /nxname (JobRunner.public_routes).
  • Auch der Job-Endpoint / ist geschützt. Clients, die Jobs per REST senden (z.B. ProxyRunner), müssen die Zugangsdaten mitschicken.
  • Der Ticker-Webserver (nwebclient.ticker) ist nicht geschützt.
  • Der Server läuft über HTTP, das Passwort wird also unverschlüsselt übertragen. Außerhalb des LANs einen Reverse-Proxy mit HTTPS (z.B. nginx, Caddy) vorschalten.

Links: Gitlab-Repo PyPi-Package

Git-URL: git@gitlab.com:bsalgert/nwebclient.git


Packaging: https://packaging.python.org/tutorials/packaging-projects/

Metadata

Release files for nwebclient 1.0.329

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nwebclient 1.0.329
File Size Uploaded Provenance Actions
nwebclient-1.0.329.tar.gz 212.7 kB Without provenance Details for nwebclient-1.0.329.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nwebclient 1.0.329
File Interpreter ABI Platform Actions
nwebclient-1.0.329-py3-none-any.whl Python 3 none any Details for nwebclient-1.0.329-py3-none-any.whl

Total release size: 411.9 kB

Release files / nwebclient-1.0.329.tar.gz

Download URL nwebclient-1.0.329.tar.gz
Size 212.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8f91480f27c3b5e689a8dbde52468ad1557b152d1ec9c8f2b25f1b6a0107286a
BLAKE2b-256 checksum
How to use checksums
62a8c69b2627ef55e44d8343acc60fcc81bde1b2547f197c30b6d2055a928e91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.2

Release files / nwebclient-1.0.329-py3-none-any.whl

Download URL nwebclient-1.0.329-py3-none-any.whl
Size 199.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f79f5ad3213b8a84244d126af8a7b627cfa4fcc0af46a12092c544608bb9992
BLAKE2b-256 checksum
How to use checksums
71f81e28bd957f17c11989c5c63674a9de882bdc32a1255d79ad18ccf11ecbe0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.2

Security for nwebclient 1.0.329

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page