Skip to main content

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")

Release files for dice-parser 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 dice-parser 1.1.0
File Size Uploaded
dice_parser-1.1.0.tar.gz 4.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dice-parser 1.1.0
File Interpreter ABI Platform
dice_parser-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / dice_parser-1.1.0.tar.gz

Download URL dice_parser-1.1.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b66891cf18e492c1eeaf8b68f1d4e4f6876d204d39cd89e40f37e5681ff5cd5a
BLAKE2b-256 checksum
How to use checksums
fb4b1a15235b833d2b1fc7ac2a9451c6db5072290db6a7ba1a9a9dfbd0b7d387
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.12.5 Linux/6.6.87.2-microsoft-standard-WSL2

Release files / dice_parser-1.1.0-py3-none-any.whl

Download URL dice_parser-1.1.0-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ca4dd5e4f71552c250d552209fde50d2a740c615b4a37cb45c37cf0876ddba4
BLAKE2b-256 checksum
How to use checksums
f2bac14c11ce1b6ea41e37b7cc1a9bcbd48ef4ac80a50a78a3fde4d3707508a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.12.5 Linux/6.6.87.2-microsoft-standard-WSL2

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0

2 release files

0.8

1 release file

0.7

1 release file

0.6

1 release file

0.5

1 release file

0.4

2 release files

0.3

1 release file

0.2

1 release file

0.1

1 release file

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