Skip to main content

A library to interact with the VTubeStudio API

Project description

A library for interacting with the VTube Studio API.

Overview

This library is intended to provide a way to interact with the VTubeStudio API while minimizing the amount of mistakes a user can make while forming Requests by having them be validated using Pydantic before.

Installation

pip install PyTubeStudio

How to Use

Start off by importing the library into your project. Because the library provides two modules, you will have to import both.

import PyTubeStudio.client as pts
import VtsModels.models as models

This basic example connects to your VTubeStudio instance, authorizes itself and asks for the current API State.

vts = pts.PyTubeStudio()

async def connect():
    await vts.connect()
    await vts.authenticate()
    answer = await vts.request(models.APIStateRequest())
    print(answer)
    await vts.close()

asyncio.run(connect())

Authorization

Every time an API client connects to your VTS instance, it will have to authorize itself. This happens via an Authorization Token. This token will be generated the first that a request is made and will be used on subsequent requests so the popup in VTS has to be accepted only once.

The token gets saved in ~/AppData/Local/PyTubeStudio/PyTubeStudio/token.txt (I dont know where the second PyTubeStudio came from). This path can be adjusted by passing another while creating the client.

vts = pts.PyTubeStudio(token_path="path")

Making Requests

All Requests are backed by corresponding Pydantic models. Heavy reference to the original VTube Studio API Reference is needed. It describes which interactions are possible and what the values actually mean.

All request models are accessed via the VtsModels module. Most requests will quickly lead to a confusing structure as they can have multiple layers of references to other models.

This is an example of injecting a singular value into a VTS parameter.

await vts.request(models.InjectParameterDataRequest(
    data=models.InjectParameterDataRequestData(
        parameter_values=[
            models.ParameterValue(
                id = "injection",
                value=avg
                )
            ]
        )
    )
)

Because this is hard to read, it is reccommended to define functions for often used requests.

async def injectValue(id, value):
    await vts.request(models.InjectParameterDataRequest(
        data=models.InjectParameterDataRequestData(
            parameter_values=[
                models.ParameterValue(
                    id = id,
                    value = value
                    )
                ]
            )
        )
    )

await injectValue("injection", 1)

This will maybe be added in the future, but currently we would rather provide a complete request feature set than one that is focused on readability.

Getting responses

The responses have been modeled as well, making the accessing of singular fields possible. To do this, the JSON that is received upon requesting has to be validated using Pydantic.

answer = await vts.request(models.APIStateRequest())

response = models.APIStateResponse.model_validate_json(answer)
print(response.data.v_tube_studio_version)

This way you can access the individual fields and receive IDE autocomplete suggestions, making accessing them easier.

Rate Limit

Tests

Currently WIP, there exists a basic Unittest that checks for positive/negative answers for all requests, however that one is specifically modeled to work with a model that I am not allowed to share, they will be adjusted to make use of the basic Hiyori model that gets shipped with VTS at some point.

Disclaimer

This is my first ever Python library and it shows, however it is feature-complete regarding the Requests and Responses as of 26.09.2024. This may change whenever the API gets updated (and doesn't include any of the event based subscriptions yet). Feel free to take any issues up with me or contribute on your own, I would love if people make use of this.

Special Thanks

I want to thank Genteki for their work on pyvts, their own take on a Python library to interact with VTS that was heavily used and referenced in the beginning of development. Special thanks to ArkStructCodes for all the help they provided during development and a lot of helpful insight.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytubestudio-0.1.0.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PyTubeStudio-0.1.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file pytubestudio-0.1.0.tar.gz.

File metadata

  • Download URL: pytubestudio-0.1.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for pytubestudio-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7acff9687b13d6805cd3e27523179137f176dc8c268d46029d93a54257750b0a
MD5 6adcf74324b84d3ea5381234faf32c56
BLAKE2b-256 1d74e0667b46a0d8f8ae909dc848fe49234f1b778fa6ad76eea09dd37cab94fc

See more details on using hashes here.

File details

Details for the file PyTubeStudio-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: PyTubeStudio-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for PyTubeStudio-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1a618462ebaba47096ee1da6cc478989170fa3ece68c3fbfe815d270b6e8f33c
MD5 31d3c17b29c34710e77c390d1b1b3a26
BLAKE2b-256 df56e142c822f10d052a985592c28d74c90b2f1bd5a95c998dfb375fc4c90eaa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page