krowvin / dokurestapi

MIT License
0 stars 0 forks source link

DokuRestAPI

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.

Features

Installation

Install the package using pip:

pip install dokurestapi

Usage

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

Examples

Login

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!")

User Management

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!")

API Reference

Login The Login class handles the login process and session management.

Users The Users class provides methods for user management.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request or open an Issue.

License

This project is licensed under the MIT License