Skip to content

AccessNamespace

pymoonraker.api.AccessNamespace

User authentication and API key management.

Auto-generated from schema/moonraker_api.yaml.

Source code in src/pymoonraker/api/_generated.py
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
class AccessNamespace:
    """User authentication and API key management.

    Auto-generated from schema/moonraker_api.yaml.
    """

    def __init__(self, client: MoonrakerClient) -> None:
        self._client = client

    async def login(self, username: str, password: str) -> AccessLoginResponse:
        """Authenticate with username and password.

        Args:
            username: Username
            password: Password

        """
        params: dict[str, Any] = {}
        params["username"] = username
        params["password"] = password
        raw = await self._client.call("access.login", params)
        return AccessLoginResponse.model_validate(raw)

    async def logout(self) -> AccessLogoutResponse:
        """Invalidate current session."""
        raw = await self._client.call("access.logout")
        return AccessLogoutResponse.model_validate(raw)

    async def get_user(self) -> AccessUserInfo:
        """Get current authenticated user info."""
        raw = await self._client.call("access.get_user")
        return AccessUserInfo.model_validate(raw)

    async def list_users(self) -> AccessUsersListResponse:
        """List all registered users."""
        raw = await self._client.call("access.users.list")
        return AccessUsersListResponse.model_validate(raw)

    async def refresh_jwt(self, refresh_token: str) -> AccessRefreshJwtResponse:
        """Refresh an expired JWT access token.

        Args:
            refresh_token: Refresh token from login

        """
        params: dict[str, Any] = {}
        params["refresh_token"] = refresh_token
        raw = await self._client.call("access.refresh_jwt", params)
        return AccessRefreshJwtResponse.model_validate(raw)

    async def get_api_key(self) -> str:
        """Get the current API key."""
        raw = await self._client.call("access.api_key")
        return cast("str", raw)

    async def oneshot_token(self) -> str:
        """Generate a single-use authentication token."""
        raw = await self._client.call("access.oneshot_token")
        return cast("str", raw)

get_api_key async

get_api_key() -> str

Get the current API key.

Source code in src/pymoonraker/api/_generated.py
654
655
656
657
async def get_api_key(self) -> str:
    """Get the current API key."""
    raw = await self._client.call("access.api_key")
    return cast("str", raw)

get_user async

get_user() -> AccessUserInfo

Get current authenticated user info.

Source code in src/pymoonraker/api/_generated.py
632
633
634
635
async def get_user(self) -> AccessUserInfo:
    """Get current authenticated user info."""
    raw = await self._client.call("access.get_user")
    return AccessUserInfo.model_validate(raw)

list_users async

list_users() -> AccessUsersListResponse

List all registered users.

Source code in src/pymoonraker/api/_generated.py
637
638
639
640
async def list_users(self) -> AccessUsersListResponse:
    """List all registered users."""
    raw = await self._client.call("access.users.list")
    return AccessUsersListResponse.model_validate(raw)

login async

login(username: str, password: str) -> AccessLoginResponse

Authenticate with username and password.

Parameters:

Name Type Description Default
username str

Username

required
password str

Password

required
Source code in src/pymoonraker/api/_generated.py
613
614
615
616
617
618
619
620
621
622
623
624
625
async def login(self, username: str, password: str) -> AccessLoginResponse:
    """Authenticate with username and password.

    Args:
        username: Username
        password: Password

    """
    params: dict[str, Any] = {}
    params["username"] = username
    params["password"] = password
    raw = await self._client.call("access.login", params)
    return AccessLoginResponse.model_validate(raw)

logout async

logout() -> AccessLogoutResponse

Invalidate current session.

Source code in src/pymoonraker/api/_generated.py
627
628
629
630
async def logout(self) -> AccessLogoutResponse:
    """Invalidate current session."""
    raw = await self._client.call("access.logout")
    return AccessLogoutResponse.model_validate(raw)

oneshot_token async

oneshot_token() -> str

Generate a single-use authentication token.

Source code in src/pymoonraker/api/_generated.py
659
660
661
662
async def oneshot_token(self) -> str:
    """Generate a single-use authentication token."""
    raw = await self._client.call("access.oneshot_token")
    return cast("str", raw)

refresh_jwt async

refresh_jwt(refresh_token: str) -> AccessRefreshJwtResponse

Refresh an expired JWT access token.

Parameters:

Name Type Description Default
refresh_token str

Refresh token from login

required
Source code in src/pymoonraker/api/_generated.py
642
643
644
645
646
647
648
649
650
651
652
async def refresh_jwt(self, refresh_token: str) -> AccessRefreshJwtResponse:
    """Refresh an expired JWT access token.

    Args:
        refresh_token: Refresh token from login

    """
    params: dict[str, Any] = {}
    params["refresh_token"] = refresh_token
    raw = await self._client.call("access.refresh_jwt", params)
    return AccessRefreshJwtResponse.model_validate(raw)