Skip to main content

A Fast Command Analyser based on Dict

Project description

Alconna

Alconna latest release Licence PyPI PyPI - Python Version

English: README

Alconna 隶属于 ArcletProject, 是 Cesloi-CommandAnalysis 的高级版, 支持解析消息链或者其他原始消息数据

Alconna 拥有复杂的解析功能与命令组件,但 一般情况下请当作[STRIKEOUT:奇妙]简易的消息链解析器/命令解析器(雾)

安装

pip

pip install --upgrade arclet-alconna

文档

文档链接: 👉指路

相关文档: 📚文档

简单使用

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") # 该方法返回一个Arpamar类的实例
print(result.get('install'))  # 或者 result.install

其结果为

{'pak_name': 'cesloi', 'upgrade': Ellipsis}

讨论

QQ 交流群: 链接

特点

  • 高效. 在 i5-10210U 处理器上, 性能大约为 41000~101000 msg/s; 测试脚本: benchmark

  • 精简、多样的构造方法

  • 强大的自动类型转换功能

  • 可传入同步与异步的 action 函数

  • 高度自定义的 HelpFormat、Analyser

  • 自定义语言文件, 支持 i18n

  • 命令输入缓存, 以保证重复命令的快速响应

  • Duplication、FuzzyMatch等一众特性

类型转换示范:

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'>
'''

模糊匹配示范:

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"?
'''

许可

Alconna 采用 MIT 许可协议

鸣谢

JetBrains: 为本项目提供 PyCharm 等 IDE 的授权 ` <https://www.jetbrains.com/>`__

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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arclet_alconna-0.9.3.1-py3-none-any.whl (66.8 kB view details)

Uploaded Python 3

File details

Details for the file arclet_alconna-0.9.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for arclet_alconna-0.9.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f2825c6fa9f3a2f49fa93900e12ffa9f825467c2940c4c1a864befcfcab08bdd
MD5 06b5916db083d8b8bde4ef9bf1663510
BLAKE2b-256 8eb9a81755ad78f4e2b7599b6defb288a1633d6c20506c61905531851d72310c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page