Skip to main content

Build Status Coverage Status Documentation Status

xdice

xdice is a lightweight python library for managing dice, scores, and dice-notation patterns.

  • Parse almost any Dice Notation pattern: ‘1d6+1’, ‘d20’, ‘3d%’, ‘1d20//2 - 2*(6d6+2)’, ‘max(1d4+1,1d6)’, ‘3D6L2’, ‘R3(1d6+1)’, ‘3dF’…etc.

  • API help you to easily manipulate dices, patterns, and scores as objects

  • A command line tool for convenience

Python Versions

xdice has been tested with python 3.4+

Documentation

For more, see the Documentation

Examples:

import dice

# Roll simple dices with rolldice()
    # eg: 2d6

score = rolldice(6, amount=2)

# manipulates the score as an integer

print(score)
>> 11
print(score * 2)
>> 22
print(score == 11)
>> True

# Or iterates over the results

for result in score:
    print(result)
>> 5
>> 6

# Parse patterns with roll() and get a PatternScore object

ps = roll("2d6+18")

print(ps)
>> 28
print(ps.format())
>> '[5,6]+18'

    # Use special notations, as selective dice
ps = roll("6D%L2")

print(ps)
>> 315
print(ps.format(verbose=True))
>> '6D%L2(scores:[80, 70, 76, 89], dropped:[2, 49])'

CLI

Run python roll.py [options] <expr>

usage: roll [-h] [-V] [-n] [-v] expression [expression ...]

Command Line Interface for the xdice library

positional arguments:
  expression      mathematical expression(s) containing dice <n>d<s> patterns

optional arguments:
  -h, --help      show this help message and exit
  -V, --version   print the xdice version string and exit
  -n, --num_only  print numeric result only
  -v, --verbose   print a verbose result

CONTRIBUTION

Any opinion / contribution is welcome, please contact us.

TO INSTALL

pip install xdice

License

xdice is under GNU License

Author

Olivier Massot, 2017

Tags

dice roll d20 game random parser dices role board

Metadata

Release files for xdice 1.2.1

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

Built distribution (wheel)

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

Release files / xdice-1.2.1-py3-none-any.whl

Download URL xdice-1.2.1-py3-none-any.whl
Size 19.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95e7afe18a6111a0497a949b7a5464596df758d5d8bd2f18279cb57d9527a399
BLAKE2b-256 checksum
How to use checksums
8877b9a0d73690e276bdd202fa186c3ed72a2e08b9df2953332f42616b2335b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.0

Security for xdice 1.2.1

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.

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