Skip to main content

brigadier.py

Implementation of Mojang/brigadier in Python.

Installing

Requires Python 3.7 or higher

# For Windows
py -3 -m pip install brigadier.py

# For linux or macOS
python3 -m pip install brigadier.py

Examples

Registering a simple command

from brigadier import CommandDispatcher
from brigadier.builder import literal, argument
from brigadier.arguments import integer

def pow2_command(ctx):
    number = ctx.get_argument("number")
    return pow(number, 2)

def pow_command(ctx):
    number = ctx.get_argument("number")
    power = ctx.get_argument("power")
    return pow(number, power)

# Register the command
dispatcher = CommandDispatcher()
dispatcher.register(
    literal("pow2").then(
        argument("number", integer).executes(power_command)
    )
)

dispatcher.register(
    literal("pow").then(
        argument("number", integer).then(
            argument("power", integer).executes(pow_command)
        )
    )
)

# Execute the command
print(dispatcher.execute("pow2 2", {}))
print(dispatcher.execute("pow 3 4", {}))

Using a custom argument type

from brigadier import CommandDispatcher
from brigadier.builder import literal, argument
from brigadier.suggestion import empty_suggestion

class Vector3:
    def parse(self, reader):
        self.x = reader.read_int()
        reader.skip()
        self.y = reader.read_int()
        reader.skip()
        self.z = reader.read_int()
        return self

    def list_suggestions(self, builder):
        return empty_suggestion()

    def get_examples(self):
        return ["2 3 1", "0 5 0"]

def teleport_command(ctx):
    location = ctx.get_argument("location")
    x = location.x
    y = location.y
    z = location.z
    print(f"You've been teleported to {x}, {y}, {z}")
    return 1

dispatcher = CommandDispatcher()
dispatcher.register(
    literal("teleport").then(
        argument("location", Vector3()).executes(teleport_command)
    )
)

dispatcher.execute("teleport 24 51 -632", {})

License

MIT

Metadata

Release files for brigadier.py 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for brigadier.py 1.1.0
File Size Uploaded Provenance Actions
brigadier.py-1.1.0.tar.gz 17.1 kB Without provenance Details for brigadier.py-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for brigadier.py 1.1.0
File Interpreter ABI Platform Actions
brigadier.py-1.1.0-py3-none-any.whl Python 3 none any Details for brigadier.py-1.1.0-py3-none-any.whl

Total release size: 44.8 kB

Release files / brigadier.py-1.1.0.tar.gz

Download URL brigadier.py-1.1.0.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8d0df5b588307ba7377ec2c981304a622dc941844eae3e8a2ebbbc1e6bed9593
BLAKE2b-256 checksum
How to use checksums
48d4dbebf31464e099c22c8465438674783294b39fe7c6a3b56f1ca3c4351895
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

Release files / brigadier.py-1.1.0-py3-none-any.whl

Download URL brigadier.py-1.1.0-py3-none-any.whl
Size 27.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
092f22dd68f33edd7410a4425f22f778390451ef2333270f01ee5c5e8cc529ea
BLAKE2b-256 checksum
How to use checksums
59a490f4ecb20225a64e50a28d6dde794e0388d6728f6982805f937590659cc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

Security for brigadier.py 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page