Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

python-nubia

Build Status

Nubia is a lightweight framework for building command-line applications with Python. It was originally designed for the “logdevice interactive shell (aka. ldshell)” at Facebook. Since then it was factored out to be a reusable component and several internal Facebook projects now rely on it as a quick and easy way to get an intuitive shell/cli application without too much boilerplate.

Nubia is built on top of python-prompt-toolkit which is a fantastic toolkit for building interactive command-line applications.

Disclaimer: Nubia is beta for non-ldshell use-cases. Some of the design decisions might sound odd but they fit the ldshell usecase perfectly. We are continuously making changes to make it more consistent and generic outside of the ldshell use-case. Until a fully stable release is published, use it on your own risk.

See the CONTRIBUTING file for how to help out.

If you are curious on the origins of the name, checkout Nubia on Wikipedia with it unique and colourful architecture.

Key Features

  • Interactive mode that offers fish-style auto-completion
  • CLI mode that gets generated from your functions and classes.
  • Optional bash/zsh completions via an external utility ‘nubia-complete’ (experimental)
  • A customisable status-bar in interactive mode.
  • An optional IPython-based interactive shell
  • Arguments with underscores are automatically hyphenated
  • Python3 type annotations are used for input type validation

Interactive mode

The interactive mode in Nubia is what makes it unique. It is very easy to build a unique shell for your program with zero overhead. The interactive shell in its simplistic form offers automatic completions for commands, sub-commands, arguments, and values. It also offers a great deal of control for developers to take control over auto-completions, even for commands that do not fall under the typical format. An example is the “select” command in ldshell which is expressed as a SQL-query. We expect that most use cases of Nubia will not need such control and the AutoCommand will be enough without further customisation.

If you start a nubia-based program without a command, it automatically starts an interactive shell. The interactive mode looks like this:

Interactive Demo

Non-interactive mode

The CLI mode is works exactly like any traditional unix-based command line utility. Non-interactive Demo

Examples

It starts with a function like this:

import socket

from termcolor import cprint
from nubia import argument, command, context

@command
@argument("hosts", description="Hostnames to resolve", aliases=["i"])
@argument("bad_name", name="nice", description="testing")
def lookup(hosts: typing.List[str], bad_name: int):
    """
    This will lookup the hostnames and print the corresponding IP addresses
    """
    ctx = context.get_context()
    print(f"hosts: {hosts}")
    cprint(f"Verbose? {}".format(ctx.verbose), "yellow")

    for host in hosts:
        cprint("{} is {}".format(host, socket.gethostbyname(host)))

    # optional, by default it's 0
    return 0

Requirements

Nubia-based applications require python 3.6+ and works with both Mac OS X or Linux. While in theory it should work on Windows, it has never been tried.

Installing Nubia

If you are installing nubia for your next project, you should be able to easily use pip for that:

pip3 install python-nubia

Building Nubia from source

Ensure is pipenv installed:

pip3 install pipenv

You can either setup.py to build a tarball, or use pipenv to setup a virtualenv with all the dependencies installed.

Running example in virtualenv:

If you would like to run the example, then you need to add the root of the source tree into your PYTHONPATH.

pipenv update --dev
pipenv shell

export PYTHONPATH="$(pwd)"
cd example/
python nubia_example.py

To run the unit tests:

pipenv run nosetests

Getting Started

See the getting started guide to learn how to build a simple application with Nubia.

License

python-nubia is BSD licensed, as found in the LICENSE file.

Download files

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

Source Distribution

python-nubia-0.1b2.tar.gz (46.8 kB view details)

Uploaded Source

Built Distribution

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

python_nubia-0.1b2-py3-none-any.whl (63.1 kB view details)

Uploaded Python 3

File details

Details for the file python-nubia-0.1b2.tar.gz.

File metadata

  • Download URL: python-nubia-0.1b2.tar.gz
  • Upload date:
  • Size: 46.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.7.0

File hashes

Hashes for python-nubia-0.1b2.tar.gz
Algorithm Hash digest
SHA256 9f0d7254376778f6e7e7e992728a066f7b5acbc0d15dc5d04e31ebb65a310cbc
MD5 a4962fb883a59cec47a006e3e77c1d03
BLAKE2b-256 9cc60fa0d2d33b00a82224233062c1f63fbb132b293baf682534364a15ab6fdb

See more details on using hashes here.

File details

Details for the file python_nubia-0.1b2-py3-none-any.whl.

File metadata

  • Download URL: python_nubia-0.1b2-py3-none-any.whl
  • Upload date:
  • Size: 63.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.7.0

File hashes

Hashes for python_nubia-0.1b2-py3-none-any.whl
Algorithm Hash digest
SHA256 39acde22176d79cc06de7051e6a4f63dcdea9400979d42b89c097b7f2968b683
MD5 42d6520526dd69c65b461f2a00d102ec
BLAKE2b-256 9e387d804c0e2ae06a460a4be06f76935a0ab9e90b67774c1a00d83b94d250c1

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