dice_parser
Arithmetic expressions with dice roll support.
dice_parser evaluates integer arithmetic expressions and common tabletop dice
notation such as d20, 2d6, 6d6h3, and 2d20L(1d1). It also keeps a
readable representation of the rolls used to compute the final value.
Installation
pip install dice-parser
Usage
from dice_parser.parser import DiceParser
parser = DiceParser()
result = parser.parse("2d6 + 4")
print(result.value)
print(result.string)
The result is a ParseResult object with two fields:
value: the evaluated integer value.string: a readable expression showing the dice that were rolled.
Supported Syntax
parser.parse("3 * 4 + 12 / 3 + (3 - 2)")
parser.parse("d20")
parser.parse("2d6 + 4")
parser.parse("6d6h3")
parser.parse("2d20L(1d1)")
parser.parse("a=2+2")
parser.parse("d a")
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dice_parser-1.1.0.tar.gz
(4.8 kB
view details)
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 dice_parser-1.1.0.tar.gz.
File metadata
- Download URL: dice_parser-1.1.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.1.4 CPython/3.12.5 Linux/6.6.87.2-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b66891cf18e492c1eeaf8b68f1d4e4f6876d204d39cd89e40f37e5681ff5cd5a
|
|
| MD5 |
17b984b3d7a63be6fad79fb92d7a600e
|
|
| BLAKE2b-256 |
fb4b1a15235b833d2b1fc7ac2a9451c6db5072290db6a7ba1a9a9dfbd0b7d387
|
File details
Details for the file dice_parser-1.1.0-py3-none-any.whl.
File metadata
- Download URL: dice_parser-1.1.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.1.4 CPython/3.12.5 Linux/6.6.87.2-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ca4dd5e4f71552c250d552209fde50d2a740c615b4a37cb45c37cf0876ddba4
|
|
| MD5 |
95b19052b0f2e21dfbda2f9ac55e450c
|
|
| BLAKE2b-256 |
f2bac14c11ce1b6ea41e37b7cc1a9bcbd48ef4ac80a50a78a3fde4d3707508a2
|