https://open5e.com
A JSON API for the D&D 5e ruleset
Table of contents generated with markdown-toc
Open5e is a community project driven by a small number of volunteers in their spare time. We welcome any and all contributions! Please join our Discord to help out: https://discord.gg/9RNE2rY or check out the issue board if you'd like to see what's being worked on!
The API uses the Django REST Framework for it's browsability and ease of use when developing CRUD endpoints. It uses django's default SQLite database, and pulls the data from the /data
directory.
Pipenv is used to install all required packages from the Pipfile
at the project root. Use the following command after cloning the project or switching branches.
pipenv install --dev
Crate a local database and import game content.
pipenv run python manage.py quicksetup --noindex
To make sure the API is always using your updated code, this command must be run again if:
- You add/remove/edit Game Content
- You edit Python code
- You switch git branches
To use the search function, you must build the search index by running the above command without the --noindex
flag.
pipenv run python manage.py quicksetup
Run the server locally. This server is only for development and shall not be used in production. The server will be available at http://localhost:8000
.
pipenv run python manage.py runserver
If you need to run the server on another port, add the port number as an argument.
pipenv run python manage.py runserver $PORT
After completing a build, you can generate an OAS file to be used by another application.
pipenv run ./manage.py generateschema --generator_class api.schema_generator.Open5eSchemaGenerator > openapi-schema.yml` to build the OAS file.
Before making any changes, you should fork the Ope5e-api repository. This will make a copy on your account, which can be freely edited. Once your edits are done you can open a Pull Request to have your changes reviewed by a maintainer, which may ask for changes or clarification before approving it. Once merged the changes go live on Beta Site before being pushed live.
Smaller edits such as spelling mistakes can be edited directly in Github. For larger edits, it is recommeded that you make changes in a full editor, such as VS Code with the Github Extenstion.
Game Content is stored in the data
directory. It is first split according to which document/source books it originated from and further into JSON files split by category e.g. "monsters.json", "spells.json". These can be edited directly. You can also add new categories to existing sources by creating the required JSON file. See an existing source, such as the 5.1 SRD to see how these should be structured.
To add a new source, create new directory inside data
and a document.json
file that credits the source and links to the license it was published under. An example of this can be found here. You can then add a json file for each category of content. See an existing source, such as the 5.1 SRD to see how these should be structured.
To load this new source, it must be added to the SOURCE_DIRS
in quickload.py. Rebuild the project to see the new Game Content.
Models such as Monsters and Classes are stored in the api/models directory. These define fields (hp, str, speed) and how they are output. The import of Game Content from data
is handled by an ImportSpec
Tests are located in the api/tests
directory. These should be run before pushing new changes to the main repository.
pipenv run pytest
The API is normally deployed via Docker. You can either build and host it yourself, or use one of the tested providers below:
This deployment has been tested using DigitalOcean Apps with Docker Hub.
To start up the server from scratch on a droplet:
git pull https://github.com/open5e/open5e-api
export SECRET_KEY=a_new_secret_key
export SERVER_NAME=whatever.yourdomain.com
cd open5e-api/
docker-compose up
- Create a fork on Github. This is used to automatically deploy whenever you make a change.
- Login with your Github account on Railway.app and give it access to manage your forked repository.
- Create a new Project and choose 'Deploy from GitHub repo'. Select your fork in the list.
- Keep all settings default and deploy. Accept when Railway asks to copy variables existing variables from the repository.
- Add the variable
PORT
with the value8888
. - Add the variable
SERVER_NAME
with the Railway-provided domain or add your own. - Push a commit to Github and watch your open5e-api redeploy in minutes!
With docker installed, you can build the project with provided Dockerfile
docker build
This docker app can then be deployed with any provider.