Skip to main content

VRoid Web API Python Wrapper

Example Usage

from sanic import Request, Sanic, json, redirect
from vroid import VRoid, VRoidOAuth

app = Sanic("VRoidApp")


@app.before_server_start
async def setup_vroid_oauth(app: Sanic, _):
    # Initialize VRoidOAuth with your client ID, secret, and redirect URI
    app.ctx.vroid_oauth = await VRoidOAuth.create(
        client_id="your_client_id_here",
        client_secret="your_client_secret_here",
        redirect_uri="http://localhost:8000/redirect",
    )


@app.route("/")
async def redirect_handler(request: Request):
    # Handle the redirect from VRoid OAuth
    url = request.app.ctx.vroid_oauth.request_to_initiate_authorization(
        response_type="code", scope="default"
    )
    return redirect(url)


@app.route("/redirect")
async def handle_redirect(request: Request):
    # Handle the redirect after authorization
    code = request.args.get("code")
    if not code:
        return json({"error": "Authorization code not provided"}, status=400)

    try:
        access_token_response = await request.app.ctx.vroid_oauth.request_access_token(
            code=code, grant_type="authorization_code"
        )
        access_token = access_token_response["access_token"]
        res = json(
            {
                "message": "Access token received successfully",
                "access_token": access_token,
            },
        )
        # NOTE: You should more securely handle the access token in production
        res.cookies.add_cookie(
            "access_token",
            access_token,
            max_age=3600,
            httponly=True,
        )
        return res
    except Exception as e:
        return json({"error": str(e)}, status=500)


@app.route("/character_models")
async def list_character_models(request: Request):
    access_token = request.cookies.get("access_token")
    if not access_token:
        return json({"error": "Access token not found"}, status=401)

    async with VRoid(access_token) as vroid:
        try:
            character_models = await vroid.list_of_character_models_posted_by_the_user()
            return json(character_models)
        except Exception as e:
            return json({"error": str(e)}, status=500)


@app.route("/revoke")
async def revoke_access_token(request: Request):
    access_token = request.cookies.get("access_token")
    if not access_token:
        return json({"error": "Access token not found"}, status=401)

    await app.ctx.vroid_oauth.revoke_access_token(token=access_token)
    return json({"message": "Access token revoked successfully"})

Metadata

Release files for VRoid 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for VRoid 0.1.1
File Size Uploaded Provenance Actions
vroid-0.1.1.tar.gz 7.3 kB Without provenance Details for vroid-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for VRoid 0.1.1
File Interpreter ABI Platform Actions
vroid-0.1.1-py3-none-any.whl Python 3 none any Details for vroid-0.1.1-py3-none-any.whl

Total release size: 17.3 kB

Release files / vroid-0.1.1.tar.gz

Download URL vroid-0.1.1.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a93c66b63356d5e572ae551b414e54c9000bedf8fb90bc78e3d2415f863d2f59
BLAKE2b-256 checksum
How to use checksums
9e535a97b341f5da3a4b7880c9bd1724a01df697f3fa2cdc8d4e7331e3e25116
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / vroid-0.1.1-py3-none-any.whl

Download URL vroid-0.1.1-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7dfd0c626e535fadfc5ce9b05cd3e3618f3700aec0f2eabf0da015aa3cc1818f
BLAKE2b-256 checksum
How to use checksums
6f99cb402f46bba24b475ffe85b8ea2bcc3aeba275be760ce73af31c2e468e5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Security for VRoid 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page