A High-performance, Generality, Humane Command Line Arguments Parser Library.
Project description
Alconna
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
$ pip install --upgrade arclet-alconna[full]
$ pip install --upgrade arclet-alconna[all]
Documentation
Official Document : 👉Link
Relevant Document : 📚Docs
A Simple Example
from arclet.alconna import Alconna, Option, Subcommand, Args
cmd = Alconna(
"/pip",
Subcommand("install", [Option("-u|--upgrade")], Args.pak_name[str]),
Option("list")
)
result = cmd.parse("/pip install cesloi --upgrade") # This method returns an 'Arparma' class instance.
print(result.query('install')) # Or result.install
Output as follows:
{'value': None, 'args': {'pak_name': 'cesloi'}, 'options': {'upgrade': Ellipsis}}
Communication
QQ Group: Link
Features
- High Performance. On i5-10210U, performance is about
71000~289000 msg/s; test script: benchmark - Simple and Flexible Constructor
- Powerful Automatic Type Parse and Conversion
- Support Synchronous and Asynchronous Actions
- Customizable Help Text Formatter, Command Analyser, etc.
- Customizable Language File, Support i18n
- Cache of input command for quick response of repeated command
- Various Features (FuzzyMatch, Command Completion, 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, CommandMeta
alc = Alconna('!test_fuzzy', "foo:str", meta=CommandMeta(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
'''
Example of Command Completion:
from arclet.alconna import Alconna, Args, Option
alc = Alconna("test", Args["bar", int]) + Option("foo") + Option("fool")
alc.parse("test --comp")
'''
next input maybe:
> foo
> int
> -h
> --help
> fool
'''
License
Alconna is licensed under the MIT License.
Acknowledgement
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file arclet-alconna-1.4.2.1.tar.gz.
File metadata
- Download URL: arclet-alconna-1.4.2.1.tar.gz
- Upload date:
- Size: 46.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.1.3 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
457a429884112c778de450307a8b2800740272e17db423bd95e5879a874770e8
|
|
| MD5 |
4832c348b89989ce6421505a65824eb0
|
|
| BLAKE2b-256 |
d9f0057e980f18e4bbe3c070fcffc5839da407f6c9c23bf1dac5a8e568b67187
|
File details
Details for the file arclet_alconna-1.4.2.1-py3-none-any.whl.
File metadata
- Download URL: arclet_alconna-1.4.2.1-py3-none-any.whl
- Upload date:
- Size: 54.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.1.3 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74cfc7cb7be816e39ef45b66e0f100cfbdc2fc66cbe2ffc908e106b3f50425f5
|
|
| MD5 |
3c9521ba12a6ac5be576c0959390aaab
|
|
| BLAKE2b-256 |
7dc6ce2d8e93684a1027a2f1743868b1f55b598008fd040deb36ce0a78131e85
|