Skip to main content

Nushell SDK to write Nushell plugins in Python easily

Project description

Nushell Python plugin SDK

⚠ Warning: this SDK is not finalized yet. While it tries to be bug-free, the architectural decisions may change in the future.

The main goal to provide a seamless integration between Nushell and Python.

Quick start

Have nu_plugin_py-quickstart.py file with the following content:

from nushell_sdk import NuPlugin


class QuickStartPlugin(NuPlugin):
    """The simplest Python plugin for Nushell."""

    name = "py-quickstart"

    def call(self, input):
        if input == "magic":
            return 42
        else:
            return 0


if __name__ == "__main__":
    QuickStartPlugin().run()

Register it:

register nu_plugin_py-quickstart.py

The registered command is py-quickstart, the usage comes from the documentation comment from the class. When the command is executed, the call method is called. The second argument is always the input, which is a native Python type. The return of the method will be the output of the Nushell command.

❯ py-quickstart
0
❯ 123 | py-quickstart
0
❯ "magic" | py-quickstart
42

Mapping between Nushell and Python types

Nushell Python
Integer int
Float float
String str
Boolean bool
Date datetime.datetime
Duration datetime.timedelta
File size FileSize (custom)
Range Range (custom)
Binary bytes
List list
Record dict
Table list of dicts
Null None
Everything else NushellObject (custom)

Raise error

If an exception raises in Python, a Nushell error is made with the relevant information and stack trace.

Parameters and signature

The parameters can be specified in signature, using the Nushell syntax for it. The signature is prefilled with basic default options, so you have to fill only the relevant parts. For more information about Nushell pulgin signature, see the Plugins chapter of the Nushell book.

If you want to provide examples, you can override the examples method.

Limitations

While Nushell plugin architecture allows to set multiple signatures (with different command name), at current implementation only one signature can be provided for a Python plugin. If you want to provide more commands, you need to split them into different Python modules

Custom encode / decode

If you have custom types in Nushell, you can override the decode_custom and encode_custom methods.

Debug your code

If you need to debug your code, you can call self.print, which prints to stderr. (stdout is used to communicate between Python and Nushell.)

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

nushell_sdk-0.0a1.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

nushell_sdk-0.0a1-py2.py3-none-any.whl (5.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file nushell_sdk-0.0a1.tar.gz.

File metadata

  • Download URL: nushell_sdk-0.0a1.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for nushell_sdk-0.0a1.tar.gz
Algorithm Hash digest
SHA256 c4d462aa4147bf84b4eea67526e3c1cc6499ecf0a9ac399f686c08d13587b30c
MD5 876376bc714d068ec9a0ea91cc7cd0fe
BLAKE2b-256 50d2641ed023dda9e571cc11d5e531a90588820485b6f23849f77858cd991105

See more details on using hashes here.

File details

Details for the file nushell_sdk-0.0a1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for nushell_sdk-0.0a1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7694de3b5d51c3d9e09d3f909c750d810424a1686e8c1adeb77a75834a6dcb7a
MD5 2cb2569c69e3b72d3addf52d310f882f
BLAKE2b-256 233eb009d858405b6470aa33151e733f4216e1396892e847f4319146034ab338

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