arclet-alconna


Namearclet-alconna JSON
Version 1.5.5 PyPI version JSON
download
home_page
SummaryA High-performance, Generality, Humane Command Line Arguments Parser Library.
upload_time2023-01-28 06:40:13
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT
keywords command argparse fast alconna cli command-line parsing optparse
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![](https://socialify.git.ci/ArcletProject/Alconna/image?description=1&descriptionEditable=A%20High-performance%2C%20Generality%2C%20Humane%20Command%20Line%20Arguments%20Parser%20Library.&font=Inter&forks=1&issues=1&language=1&logo=https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F42648639%3Fs%3D400%26u%3Da81d93f3683d0a3b7d38ea8e6a4903355986e8c7%26v%3D4&name=1&owner=1&pattern=Brick%20Wall&stargazers=1&theme=Light)

<div align="center"> 

# Alconna

</div>

![Alconna](https://img.shields.io/badge/Arclet-Alconna-2564c2.svg)
![latest release](https://img.shields.io/github/release/ArcletProject/Alconna)
[![Licence](https://img.shields.io/github/license/ArcletProject/Alconna)](https://github.com/ArcletProject/Alconna/blob/master/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/arclet-alconna)](https://pypi.org/project/arclet-alconna)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/arclet-alconna)](https://www.python.org/)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FArcletProject%2FAlconna.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FArcletProject%2FAlconna?ref=badge_shield)

[**简体中文**](README.md)|[**English**](README-EN.md)

## 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
```shell
$ pip install --upgrade arclet-alconna
$ pip install --upgrade arclet-alconna[full]
$ pip install --upgrade arclet-alconna[all]
```

## Documentation

Official Document : [👉Link](https://arcletproject.github.io/docs/alconna/tutorial)

Relevant Document : [📚Docs](https://graiax.cn/guide/message_parser/alconna.html)

## A Simple Example

```python
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 numpy --upgrade") # This method returns an 'Arparma' class instance.
print(result.query('install'))  # Or result.install
```

Output as follows:
```
value=None args={'pak_name': 'numpy'} options={'upgrade': value=Ellipsis args={}} subcommands={}
```

## Communication

QQ Group: [Link](https://jq.qq.com/?_wv=1027&k=PUPOnCSH)

## Features

* High Performance. On i5-10210U, performance is about `71000~289000 msg/s`; test script: [benchmark](benchmark.py) 
* 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:

```python
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:

```python
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:
```python
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:
```python
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](LICENSE).

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FArcletProject%2FAlconna.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FArcletProject%2FAlconna?ref=badge_large)

## Acknowledgement

[JetBrains](https://www.jetbrains.com/): Support Authorize for [PyCharm](https://www.jetbrains.com/pycharm/)<br>
[<img src="https://cdn.jsdelivr.net/gh/Kyomotoi/CDN@master/noting/jetbrains-variant-3.png" width="200"/>](https://www.jetbrains.com/)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "arclet-alconna",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "command,argparse,fast,alconna,cli,command-line,parsing,optparse",
    "author": "",
    "author_email": "RF-Tar-Railt <rf_tar_railt@qq.com>",
    "download_url": "https://files.pythonhosted.org/packages/d6/22/d4c9c82f05b47262d0aeedabf4b5d50456da2c61b8dc808ab9bb66a2af46/arclet-alconna-1.5.5.tar.gz",
    "platform": null,
    "description": "![](https://socialify.git.ci/ArcletProject/Alconna/image?description=1&descriptionEditable=A%20High-performance%2C%20Generality%2C%20Humane%20Command%20Line%20Arguments%20Parser%20Library.&font=Inter&forks=1&issues=1&language=1&logo=https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F42648639%3Fs%3D400%26u%3Da81d93f3683d0a3b7d38ea8e6a4903355986e8c7%26v%3D4&name=1&owner=1&pattern=Brick%20Wall&stargazers=1&theme=Light)\n\n<div align=\"center\"> \n\n# Alconna\n\n</div>\n\n![Alconna](https://img.shields.io/badge/Arclet-Alconna-2564c2.svg)\n![latest release](https://img.shields.io/github/release/ArcletProject/Alconna)\n[![Licence](https://img.shields.io/github/license/ArcletProject/Alconna)](https://github.com/ArcletProject/Alconna/blob/master/LICENSE)\n[![PyPI](https://img.shields.io/pypi/v/arclet-alconna)](https://pypi.org/project/arclet-alconna)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/arclet-alconna)](https://www.python.org/)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FArcletProject%2FAlconna.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FArcletProject%2FAlconna?ref=badge_shield)\n\n[**\u7b80\u4f53\u4e2d\u6587**](README.md)|[**English**](README-EN.md)\n\n## About\n\n`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`.\n\n`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.\n\n## Installation\n\npip\n```shell\n$ pip install --upgrade arclet-alconna\n$ pip install --upgrade arclet-alconna[full]\n$ pip install --upgrade arclet-alconna[all]\n```\n\n## Documentation\n\nOfficial Document : [\ud83d\udc49Link](https://arcletproject.github.io/docs/alconna/tutorial)\n\nRelevant Document : [\ud83d\udcdaDocs](https://graiax.cn/guide/message_parser/alconna.html)\n\n## A Simple Example\n\n```python\nfrom arclet.alconna import Alconna, Option, Subcommand, Args\n\ncmd = Alconna(\n    \"/pip\",\n    Subcommand(\"install\", Option(\"-u|--upgrade\"), Args.pak_name[str]),\n    Option(\"list\")\n)\n\nresult = cmd.parse(\"/pip install numpy --upgrade\") # This method returns an 'Arparma' class instance.\nprint(result.query('install'))  # Or result.install\n```\n\nOutput as follows:\n```\nvalue=None args={'pak_name': 'numpy'} options={'upgrade': value=Ellipsis args={}} subcommands={}\n```\n\n## Communication\n\nQQ Group: [Link](https://jq.qq.com/?_wv=1027&k=PUPOnCSH)\n\n## Features\n\n* High Performance. On i5-10210U, performance is about `71000~289000 msg/s`; test script: [benchmark](benchmark.py) \n* Simple and Flexible Constructor \n* Powerful Automatic Type Parse and Conversion\n* Support Synchronous and Asynchronous Actions\n* Customizable Help Text Formatter, Command Analyser, etc.\n* Customizable Language File, Support i18n\n* Cache of input command for quick response of repeated command\n* Various Features (FuzzyMatch, Command Completion, etc.)\n\nExample of Type Conversion:\n\n```python\nfrom arclet.alconna import Alconna, Args\nfrom pathlib import Path\n\nread = Alconna(\n    \"read\", Args[\"data\", bytes], \n    action=lambda data: print(type(data))\n)\n\nread.parse([\"read\", b'hello'])\nread.parse(\"read test_fire.py\")\nread.parse([\"read\", Path(\"test_fire.py\")])\n\n'''\n<class 'bytes'>\n<class 'bytes'>\n<class 'bytes'>\n'''\n```\n\nExample of FuzzyMatch:\n\n```python\nfrom arclet.alconna import Alconna, CommandMeta\n\nalc = Alconna('!test_fuzzy', \"foo:str\", meta=CommandMeta(fuzzy_match=True))\nalc.parse(\"\uff01test_fuzy foo bar\")\n\n'''\n\uff01test_fuzy not matched. Are you mean \"!test_fuzzy\"?\n'''\n```\n\n\nExample of `typing` Support:\n```python\nfrom typing import Annotated  # or typing_extensions.Annotated\nfrom arclet.alconna import Alconna, Args\n\nalc = Alconna(\"test\", Args.foo[Annotated[int, lambda x: x % 2 == 0]])\nalc.parse(\"test 2\")\nalc.parse(\"test 3\")\n\n'''\n'foo': 2\nParamsUnmatched: param 3 is incorrect\n'''\n```\n\n\nExample of Command Completion:\n```python\nfrom arclet.alconna import Alconna, Args, Option\n\nalc = Alconna(\"test\", Args[\"bar\", int]) + Option(\"foo\") + Option(\"fool\")\nalc.parse(\"test --comp\")\n\n'''\nnext input maybe:\n> foo\n> int\n> -h\n> --help\n> fool\n'''\n```\n\n## License\n\nAlconna is licensed under the [MIT License](LICENSE).\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FArcletProject%2FAlconna.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2FArcletProject%2FAlconna?ref=badge_large)\n\n## Acknowledgement\n\n[JetBrains](https://www.jetbrains.com/): Support Authorize for [PyCharm](https://www.jetbrains.com/pycharm/)<br>\n[<img src=\"https://cdn.jsdelivr.net/gh/Kyomotoi/CDN@master/noting/jetbrains-variant-3.png\" width=\"200\"/>](https://www.jetbrains.com/)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A High-performance, Generality, Humane Command Line Arguments Parser Library.",
    "version": "1.5.5",
    "split_keywords": [
        "command",
        "argparse",
        "fast",
        "alconna",
        "cli",
        "command-line",
        "parsing",
        "optparse"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8c84a4c0503b85bc0f8fd18775f9cb5443661d189d603a2cf5e8f0e4f6db72c9",
                "md5": "5d717837118e7dcf8e465620532c61ce",
                "sha256": "b1b17c336cad5b2bf18a4be4c4f304ed18aad5b89b308683020d0e004a6304f6"
            },
            "downloads": -1,
            "filename": "arclet_alconna-1.5.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5d717837118e7dcf8e465620532c61ce",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 57205,
            "upload_time": "2023-01-28T06:40:03",
            "upload_time_iso_8601": "2023-01-28T06:40:03.075033Z",
            "url": "https://files.pythonhosted.org/packages/8c/84/a4c0503b85bc0f8fd18775f9cb5443661d189d603a2cf5e8f0e4f6db72c9/arclet_alconna-1.5.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d622d4c9c82f05b47262d0aeedabf4b5d50456da2c61b8dc808ab9bb66a2af46",
                "md5": "3bb8ef928bd54645041595d1faaddb48",
                "sha256": "71a73c73ff414ecf09ac6fa27b89511164fdf8c199b1e7f12454cb5f1947f8e6"
            },
            "downloads": -1,
            "filename": "arclet-alconna-1.5.5.tar.gz",
            "has_sig": false,
            "md5_digest": "3bb8ef928bd54645041595d1faaddb48",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 47657,
            "upload_time": "2023-01-28T06:40:13",
            "upload_time_iso_8601": "2023-01-28T06:40:13.546490Z",
            "url": "https://files.pythonhosted.org/packages/d6/22/d4c9c82f05b47262d0aeedabf4b5d50456da2c61b8dc808ab9bb66a2af46/arclet-alconna-1.5.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-28 06:40:13",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "arclet-alconna"
}
        
Elapsed time: 0.12636s