Skip to main content

A High-performance, Generality, Humane Command Line Arguments Parser Library.

Reason this release was yanked:

bugs

Project description

Alconna

Alconna latest release Licence PyPI PyPI - Python Version FOSSA Status

������������|English

About

Alconna is a powerful cli tool for parsing message chain or other raw message data. It is an overload version of CommandAnalysis, affiliated to ArcletProject.

Alconna has a large number of built-in components and complex parsing functions. But do not afraid, you can use it as a simple command parser.

Installation

pip

$ pip install --upgrade arclet-alconna

Documentation

Official Document : ����Link

Relevant Document : ����Docs

A Simple Example

from arclet.alconna import Alconna, Option, Subcommand, Args

cmd = Alconna(
    "/pip",
    options=[
        Subcommand("install", [Option("-u|--upgrade")], Args.pak_name[str]),
        Option("list"),
    ]
)

result = cmd.parse("/pip install cesloi --upgrade") # This method returns an 'Arpamar' class instance.
print(result.query('install'))  # Or result.install

Output as follows:

{'value': None, 'args': {'pak_name': 'cesloi'}, 'options': {'upgrade': Ellipsis}}

With Simple Callback

from arclet.alconna import Alconna, Option, Args
from arclet.alconna.builtin.construct import ALCCommand

def send_message(message: str, to: str = None):
    print(f"sending {message} to {to}")

command = ALCCommand(
    Alconna("send_message", Args.message[str]) + Option("-t|--to", Args.to[str]),
    send_message
)

command("send_message -t Alconna hello")

Output as follows:

sending hello to Alconna

Communication

QQ Group: Link

Features

  • High Performance. On i5-10210U, performance is about 41000~101000 msg/s; test script: benchmark
  • Simple and Flexible Constructor
  • Powerful Automatic Type Parse and Conversion
  • Support Synchronous and Asynchronous Actions
  • Customizable HelpFormatter and Analyser
  • Customizable Language File, Support i18n
  • Cache of input command for quick response of repeated command
  • Various Features (Duplication, FuzzyMatch, etc.)

Example of Type Conversion:

from arclet.alconna import Alconna, Args
from pathlib import Path

read = Alconna(
    "read", Args["data", bytes], 
    action=lambda data: print(type(data))
)

read.parse(["read", b'hello'])
read.parse("read test_fire.py")
read.parse(["read", Path("test_fire.py")])

'''
<class 'bytes'>
<class 'bytes'>
<class 'bytes'>
'''

Example of FuzzyMatch:

from arclet.alconna import Alconna
alc = Alconna('!test_fuzzy', "foo:str", is_fuzzy_match=True)
alc.parse("���test_fuzy foo bar")

'''
���test_fuzy not matched. Are you mean "!test_fuzzy"?
'''

Example of typing Support:

from typing import Annotated  # or typing_extensions.Annotated
from arclet.alconna import Alconna, Args

alc = Alconna("test", Args.foo[Annotated[int, lambda x: x % 2 == 0]])
alc.parse("test 2")
alc.parse("test 3")

'''
'foo': 2
ParamsUnmatched: param 3 is incorrect
'''

License

Alconna is licensed under the MIT License.

FOSSA Status

Acknowledgement

JetBrains: Support Authorize for PyCharm

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

arclet-alconna-1.2.0.3.tar.gz (53.3 kB view hashes)

Uploaded Source

Built Distribution

arclet_alconna-1.2.0.3-py3-none-any.whl (63.0 kB view hashes)

Uploaded Python 3

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