Skip to main content

Yet another dice roller for Python.

Project description

Another common RPG die rolling syntax random number generator.

Why did you do this?

That’s a very good question. I guess the answer is that I started just to see if I could, and it snowballed from there. In order to explore Python, I had built a few packages in the past that would randomly generate table top role playing game (TTRPG) characters. Each of them had a version of a dice rolling module I had written, so I had this code in a bunch of places.

“I’ll make that a package!” I thought.

But, wait, what if I want to use dice from different game systems? I had run across Backus Naur form (BNF) descriptions of languages in the past when looking into algorithms, and it seemed like writing a parser to handle different dice systems seemed a reasonable way to go. As reasonable as any thought involving, “I’ll use BNF here,” can be, I guess. And so was born Yet Another Dice Notation (YADN) and yadr.

For a description of YADN see: YADN

Do we need another Python dice rolling package?

No. Probably not. Unsurprisingly, there seems to be a lot of people who play TTRPGs and write Python packages. This is yet another one.

Hence the name.

Does it support my game?

Check through the YADN doc to see if the operations you need are described there. If not, open an issue, and I’ll see what I can do.

Why does it require Python 3.10?

Another reason for this package is I wanted a project to explore the new match case feature in Python 3.10. I’d read that parsing is one of the cases where it’s really useful.

So, I implemented it.

Then I removed it.

The problem isn’t with match case. It worked well enough, and I think the syntax was fairly clear. I’m not really sure it bought me anything over using if…elif…else, but I think that is because everything I’m lexing or parsing is fairly simple. More complex cases my see greater benefit from match…case.

The problem is with mypy. It doesn’t support match case yet. So, my options were:

  1. Ditch mypy,

  2. Mark all the match blocks as type: ignore,

  3. Go back to if.

Option 2 was just a mess in the code.

My impression is that mypy is still here to stay, so I want to try to make things work with it.

So, I went back to if, at least until mypy better supports match case.

Since I removed the match case, I can probably lower the Python requirement to 3.7 or so. If anyone ever uses this, I’ll think about it. For now, I’m only testing it under a 3.10 virtual environment, so I’ll keep it at 3.10.

How do I use this package?

If you want to execute the package from the command line, you can install the package using pip or other Python package manager, and run it as a module with the following:

python -m yadr <YADN_string>

If you want to import it into your own code, install and import the package as usual. You can then use the roll() function in the yadr module to execute a string of YADN.:

>>> import yadr
>>>
>>> yadn = '3d6'
>>> result = yadr.roll(yadn)

How do I run the tests?

I’m using the pytest library for the unit tests. To just run those tests, go to the root of your clone of the yadr repository and use the following command:

python3 -m pytest

The full suite of style checks, mypy, and such I use can be run using a shortcut I have set up in the Makefile:

make pre

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yadr-0.1.6.tar.gz (32.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yadr-0.1.6-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

Details for the file yadr-0.1.6.tar.gz.

File metadata

  • Download URL: yadr-0.1.6.tar.gz
  • Upload date:
  • Size: 32.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for yadr-0.1.6.tar.gz
Algorithm Hash digest
SHA256 c3e809f9c8f85e1e6fd9786e50a2086644670c8f0d90b7842d7caf53e226047d
MD5 bdd33c3a23f1d73a5fbfb09216c3b6fe
BLAKE2b-256 b5075c77b2d7a349e59fc3ddf27845e58adb2d661f69ece0dbec48345b681e9b

See more details on using hashes here.

File details

Details for the file yadr-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: yadr-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for yadr-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 de9b5535d4e0071736fceb28b3da6a07ef60fb58f9817e0b29930d695e71a526
MD5 4c0c06638c2d796d8cc17979750e4413
BLAKE2b-256 ffc5accacf72d538ee0fa49f72af961c2fba6354199e248c003eaed76cb93e98

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page