DokuRestAPI is a Python package that provides an easy-to-use interface for interacting with the DokuWiki web interface via its undocumented REST API. This package allows you to perform actions such as creating and deleting users, fetching user details, and managing other aspects of your DokuWiki instance programmatically.
If you would like to see other things added create an issue! I've just been adding things as I need them.
Install the package using pip:
pip install dokurestapi
First, make sure you have a .env file in your project directory with your DokuWiki credentials:
DOKUWIKI_USERNAME=your_dokuwiki_username
DOKUWIKI_PASSWORD=your_dokuwiki_password
DOMAIN=https://path.toyourdoku.domain/andorsubdir
from dokurestapi.Login import Login
# Load credentials from .env file
import os
from dotenv import load_dotenv
load_dotenv()
username = os.getenv("DOKUWIKI_USERNAME")
password = os.getenv("DOKUWIKI_PASSWORD")
domain = os.getenv("DOMAIN")
with Login(username, password, domain) as login_session:
if login_session.is_logged_in():
print("Logged in successfully!")
else:
print("Login failed!")
from dokurestapi import Login, Users
# Load credentials from .env file
import os
from dotenv import load_dotenv
load_dotenv()
username = os.getenv("DOKUWIKI_USERNAME")
password = os.getenv("DOKUWIKI_PASSWORD")
domain = os.getenv("DOMAIN")
with Login(username, password, domain) as login_session:
if login_session.is_logged_in():
users = Users(login_session.session)
# Get all users
all_users = users.get_users()
print(all_users)
# Add a new user
new_user = users.add_user(
userid="newuser",
username="New User",
password="securepassword", # Leave blank to have it generate one!
email="newuser@example.com",
notify=True,
groups=["user"]
)
print(new_user)
else:
print("Login failed!")
Login The Login class handles the login process and session management.
Login(username, password, domain)
: Initializes the login class with the given credentials.login(username=None, password=None)
: Logs in to DokuWiki. You can override the username and password.logout()
: Logs out from DokuWiki and allows you to login as another user in the same script runis_logged_in()
: Returns True if logged in, False otherwise.get_username()
: Returns the username of the logged-in user.Users The Users class provides methods for user management.
get_user(username)
: Fetches details of a specific user.get_users()
: Fetches a list of all users.add_user(userid, username, password, email, notify=True, groups=["user"])
: Adds a new user with the specified details.Contributions are welcome! Please feel free to submit a Pull Request or open an Issue.
This project is licensed under the MIT License