Skip to main content

An HCLI Connector that can be used to expose a REST API as a CLI, via hypertext command line interface (HCLI) semantics.

Project description

pypi build status pyver huckle hc hg

HCLI Core

An HCLI Connector that can be used to expose a REST API as a CLI, via hypertext command line interface (HCLI) semantics.


HCLI Core implements an HCLI Connector, a type of Service Connector, as a WSGI application and provides a way for developers to expose a service hosted CLI, as a REST API, via HCLI semantics. Such an API exposes a “built-in” CLI that can be interacted with dynamically with any HCLI client. Up to date, in-band, man page style API/CLI documentation is readily available for use to help understand how to interact with the API.

Most, if not all, programming languages have a way to issue shell commands. With the help of a generic HCLI client, such as Huckle [1], APIs that make use of HCLI semantics are readily consumable anywhere via the familiar command line (CLI) mode of operation, and this, without there being a need to write a custom and dedicated CLI to interact with a specific HCLI API.

You can find out more about HCLI on hcli.io [2]

The HCLI Internet-Draft [3] is a work in progress by the author and the current implementation leverages hal+json alongside a static form of ALPS (semantic profile) [4] to help enable widespread cross media-type support.

Help shape HCLI and it’s ecosystem by raising issues on github!

[1] https://github.com/cometaj2/huckle

[2] http://hcli.io

[3] https://github.com/cometaj2/I-D/tree/master/hcli

[4] http://alps.io

Installation

hcli_core requires a supported version of Python and pip.

You’ll need an WSGI compliant application server to run hcli_core. For example, you can use Green Unicorn (https://gunicorn.org/), and an HCLI client such as Huckle (https://github.com/cometaj2/huckle). The following runs the default jsonf HCLI bundled with HCLI Core.

pip install hcli-core
pip install gunicorn
pip install huckle
gunicorn --workers=5 --threads=2 -b 127.0.0.1:8000 "hcli_core:connector()"

Usage

Open a different shell window.

Setup the huckle env eval in your .bash_profile (or other bash configuration) to avoid having to execute eval everytime you want to invoke HCLIs by name (e.g. jsonf).

Note that no CLI is actually installed by Huckle. Huckle reads the HCLI semantics exposed by the API and ends up behaving like the CLI it targets.

huckle cli install http://127.0.0.1:8000
eval $(huckle env)
jsonf help

3rd Party HCLI Installation

If you want to load a sample HCLI other than the default sample application, you can try loading one of the other sample HCLIs developped independently of HCLI Core. For example, the hc HCLI (hypertext GPT-3.5-Turbo command line chat application).

A folder path to any other 3rd party HCLI can be provided in the same way to the HCLI Connector, provided the 3rd party HCLI meets CLI interface (cli.py) and HCLI template (template.json) requirements:

pip install hcli-hg
pip install hcli-core
pip install gunicorn
pip install huckle
gunicorn --workers=5 --threads=2 "hcli_core:connector(\"`hcli_hg path`\")"

3rd Party HCLI Usage

Open a different shell window.

Setup the huckle env eval in your .bash_profile (or other bash configuration) to avoid having to execute eval everytime you want to invoke HCLIs by name (e.g. hg).

huckle cli install http://127.0.0.1:8000
eval $(huckle env)
hg help

Versioning

This project makes use of semantic versioning (http://semver.org) and may make use of the “devx”, “prealphax”, “alphax” “betax”, and “rcx” extensions where x is a number (e.g. 0.3.0-prealpha1) on github. Only full major.minor.patch releases will be pushed to pip from now on.

Supports

  • HTTP/HTTPS.

  • HCLI version 1.0 server semantics for hal+json

  • Web Server Gateway Interface (WSGI) through PEP 3333 and Falcon.

  • Bundled Sample HCLIs:
    • jsonf - a simple formatter for JSON.

    • hfm - a file upload and download manager that works with *nix terminal shell input and output streams.

    • hptt - a rudimentary HCLI Push To Talk (PTT) channel management service.

    • hub - a rudimentary HCLI service discovery hub.

    • nw - a flexible IP Address Management (IPAM) service.

  • Support for use of any 3rd party HCLI code that meets CLI interface requirements and HCLI template requirements (i.e. see sample HCLIs).

  • Support large input and output streams as application/octet-stream.

To Do

  • Automated tests for all bundled HCLI samples.

  • Separate out HCLI applications from HCLI Core to help avoid application dependencies bleeding onto HCLI Core.

Bugs

  • No good handling of control over request and response in cli code which can lead to exceptions and empty response client side.

  • The hfm sample HCLI fails disgracefully when copying a remote file name that doesn’t exist (server error).

Project details


Release history Release notifications | RSS feed

This version

1.0.3

Download files

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

Source Distribution

hcli_core-1.0.3.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

hcli_core-1.0.3-py2.py3-none-any.whl (36.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file hcli_core-1.0.3.tar.gz.

File metadata

  • Download URL: hcli_core-1.0.3.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.9

File hashes

Hashes for hcli_core-1.0.3.tar.gz
Algorithm Hash digest
SHA256 f0da49026483a4aef34d9fc4761a7e8eab672a5c54a51741442e10fa71f79821
MD5 cf170d5ea4fd544821c9be2aa81a8667
BLAKE2b-256 c42640f9c8ce2918d3c5cacb6cdcbef4cf947956bd30e19a8e45155821b8f0e1

See more details on using hashes here.

File details

Details for the file hcli_core-1.0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: hcli_core-1.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 36.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.9

File hashes

Hashes for hcli_core-1.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bc1f167e4e1b7a66ee83af0b23ce79c1eab90239a5e17edc80978d7e3e183d8e
MD5 024f0c345d85e8c185e91036feace029
BLAKE2b-256 642e57cc32e3c0cb6a58ed5c80b40e317f8d1c1e9a6039af92a010335d37ddb3

See more details on using hashes here.

Supported by

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