PyHedrals 
A library for evaluating tabletop dice roll expressions.
Used in the Mastodon bot DiceCat, and the IRC bot DesertBot
Usage Overview
Sample usage:
5d6!>4 + (5d(2d10)dl - d10) * (d20 / 2) # for an unnecessarily complicated roll
Sample output:
84 for an unnecessarily complicated roll
There is also a verbose mode that outputs every individual die roll, that output looks like this:
[2d10: 2,5 (7) | 5d7: -1-,6,2,4,5 (17) | 1d10: 3 (3) | 1d20: 9 (9) | 5d6: 2,2,3,*5*,*5*,2,*5*,4 (28)] 84 for an unnecessarily complicated roll
Supported Operators
- Arithmetic:
+-*/%^()(addition, subtraction, multiplication, division, modulus, exponent, parentheses) - Dice:
#d#(eg,3d6,d20)- Rolls the left number of dice with the right number of sides.
3d6rolls 3 six-sided dice - The first number is optional and defaults to 1 if omitted
- Rolls the left number of dice with the right number of sides.
- Dice modifiers:
- Keep/Drop Highest/Lowest:
kh#kl#dh#dl#- Keeps/Drops only the # highest/lowest dice rolls. Any that are either not kept or dropped are removed from the total
- The number is optional and defaults to 1 if omitted
- Exploding:
!!#!>#!>=#!<#!<=#- Each die that rolls maximum (
!), or a specific number (!#), or over/under a threshold (!>#!>=#!<#!<=#), adds an additional die to the pool- This repeats for each die added to the pool
- Each die that rolls maximum (
- Reroll:
rr#r>#r>=#r<#r<=#- Drops and rerolls each die that rolls minimum (
r), or a specific number (r#), or over/under a threshold (r>#r>=#r<#r<=#)- This repeats for each die rerolled. You can make it only reroll each die once with
roinstead ofr
- This repeats for each die rerolled. You can make it only reroll each die once with
- Drops and rerolls each die that rolls minimum (
- Count:
cc#c>#c>=#c<#c<=#- Counts the number of dice that roll maximum (
c), or a specific number (c#), or over/under a threshold (c>#c>=#c<#c<=#)
- Counts the number of dice that roll maximum (
- Sorting:
ssasd- Sorts the dice rolls in ascending (
ssa) or descending (sd) order - This still applies in non-verbose mode but you won't see any visible effect
- Sorts the dice rolls in ascending (
- Keep/Drop Highest/Lowest:
- Comments:
# your comment here- Adds a comment to the end of the output, so you can describe what the roll is for. eg:
d20+5 # for initiative - The
#is a literal hash, not a number this time :)
- Adds a comment to the end of the output, so you can describe what the roll is for. eg:
If you have more ideas for operators, suggestions and pull requests are welcome!
Metadata
Release files for pyhedrals 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyhedrals-0.2.0.tar.gz | 6.3 kB | Without provenance | Details for pyhedrals-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyhedrals-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for pyhedrals-0.2.0-py3-none-any.whl |
Total release size: 13.6 kB
Release files / pyhedrals-0.2.0.tar.gz
| Download URL | pyhedrals-0.2.0.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bbbb4fe25fbd056669417943bbf18d16faed44a435102c6e87fcfe5580e3c669
|
|
BLAKE2b-256 checksum How to use checksums |
9dbb82de26b7f4fe4433dd0134de1be3b2a462ad1fd83db1cfa4a0a566c4698f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.7
|
Release files / pyhedrals-0.2.0-py3-none-any.whl
| Download URL | pyhedrals-0.2.0-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
90ecbc1d352e7a459d4fb365bc3c7f097bf563f0573b56265361e50542b08948
|
|
BLAKE2b-256 checksum How to use checksums |
6017adefb957c1dcf39d2a0aab957adf439de9a0e63e71581f2f51294094736f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.7
|
Security for pyhedrals 0.2.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.