python-nubia

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:

Non-interactive mode

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

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.

python interactive mode_Nubia:是一个用Python构建命令行和交互式shell应用的轻量级框架...相关推荐

  1. linux shell用户交互,鱼 - 一个明智的和用户友好的交互式shell为Linux

    友好的交互式shell被称为和简称FISH是UNIX和类UNIX操作系统的壳. 它是一种独特而新颖的命令行环境与一些有益的改进. 鱼的设计与任何其他的shell,比如bash或者zsh来工作. 不像在 ...

  2. js和python交互_JSShell:一个基于python的交互式Shell

    JSShell 本文将给大家介绍一款基于Web的多用户交互式Shell,该工具采用Python语言编写,服务器端使用的是Flask框架,而客户端当然就是JavaScript和HTML组成的了.我当初在 ...

  3. python查天气预报_一个用Python编写抓取天气预报的代码示例

    Python代码抓取获取天气预报信息源码讲解.这是一个用Python编写抓取天气预报的代码示例,用python写天气查询软件程序很简单.这段代码可以获取当地的天气和.任意城市的天气预报,原理是根据ur ...

  4. python 游戏辅助lol_一个基于python的自动玩游戏辅助

    文章目录 一.背景 场景分析 二.方案选择 方案对比: 三.设计思路 四.代码撸起来 五.工具效果 我的心得 一.背景 业余时间我会玩一玩游戏,然而并不是所有所有的游戏内容都会让我一直保持着兴趣.一段 ...

  5. python 在末尾增加一个字符串,python - Python File.write在末尾添加额外的字符串 - SO中文参考 - www.soinside.com...

    我正在使用python(3.6)更新文本文件,并打开r +with open(f+'.play', 'r+') as f2: play = f2.read() result = manipulate( ...

  6. python垃圾语言-分享一个用python写的window清理缓存垃圾小程序

    [Python] 纯文本查看 复制代码# coding: utf-8 import os import shutil del_extension = [".tmp", " ...

  7. python国际象棋规则_python-chess: 一个纯Python国际象棋库

    python-chess: a pure Python chess library

  8. python 爬虫 教程_一个入门级python爬虫教程详解

    前言 本文目的:根据本人的习惯与理解,用最简洁的表述,介绍爬虫的定义.组成部分.爬取流程,并讲解示例代码. 基础 爬虫的定义:定向抓取互联网内容(大部分为网页).并进行自动化数据处理的程序.主要用于对 ...

  9. python英文分词库_smallseg---又一个开源python分词库

    可自定义词典.返回登录词列表和未登录词列表.有一定的新词识别能力. tutorial: s3 = file("text.txt").read() words = [x.rstrip ...

最新文章

  1. MBTiles离线包生成和使用
  2. PHP匹配函数怎么用,php preg_match_all函数怎么用
  3. sqoop操作之Oracle导入到HDFS
  4. Java编程经典10道_Java经典编程题50道之十二
  5. Navicat Premium 安装
  6. 【Eclipse】Eclipse-Build-缓慢-卡住
  7. jQuery 中文文档
  8. scv文件单元格内存在换行符
  9. 宾夕法尼亚大学发明了第一代电子管计算机,新手计算机基础入门
  10. 县级外业调查及举证软件_MapGIS第三次国土调查系列产品
  11. 桌面图标无法删除之解决方案
  12. android画布橡皮,Android 橡皮擦功能的实现
  13. 【不积跬步_无以至千里】 数学知识(不定时整理)
  14. 我为什么鼓励工程师写博客
  15. JAVA图片裁剪上传实例______软件开发-帮助类
  16. cvs数据格式 gps_运动手表GPS轨迹文件导出方法
  17. gantt/甘特图完整代码(带注释,可以复制)
  18. android免root管理自动启动不了,真正免root的Autostarts(管理自启)详细使用教程...
  19. Neo4j导入本地CSV文件三元组关系生成图谱
  20. 2021年工业软件行业研究报告

热门文章

  1. 程序员应不应该背锅?
  2. 使用C#实现WinForm窗体的动画效果
  3. vue 页面动态切换title keywords description (seo的设置)
  4. 微软x64常用汇编指令总结
  5. IntelliJ IDEA 如何彻底删除项目的步骤
  6. Uibot(来也RPA)使用在目标中输入密码总是报错
  7. 2022年最佳电动汽车、最佳新车榜单:特斯拉、大众、梅赛德斯、日产等车型入选 | 美通社头条...
  8. javaweb入门知识点总结(上)
  9. CMOS Image Sensor的MIPI CSI接口介绍及波形实测
  10. play chess象棋