Skip to content

Models Reference

Classes:

Name Description
AudioFormat

List of audio formats accepted by Flowery.

FloweryAPIConfig

Configuration used when making requests to the Flowery API.

Language

Language object returned from the Flowery API.

TTSResponse

Object containing data from a TTS query.

Voice

Voice object returned from the Flowery API.

AudioFormat

Bases: str, Enum

List of audio formats accepted by Flowery.

Attributes:

Name Type Description
AAC

AAC audio format.

FLAC

FLAC audio format.

MP3

MP3 audio format.

OPUS

OGG Opus audio format.

VORBIS

OGG Vorbis audio format.

WAV

WAV audio format.

Source code in pyflowery/models.py
class AudioFormat(str, Enum):
    """List of audio formats accepted by Flowery."""

    MP3 = "mp3"
    "[MP3](https://en.wikipedia.org/wiki/MP3) audio format."
    OPUS = "ogg_opus"
    "[OGG](https://en.wikipedia.org/wiki/Ogg) [Opus](https://en.wikipedia.org/wiki/Opus_(audio_format)) audio format."
    VORBIS = "ogg_vorbis"
    "[OGG](https://en.wikipedia.org/wiki/Ogg) [Vorbis](https://en.wikipedia.org/wiki/Vorbis) audio format."
    AAC = "aac"
    "[AAC](https://en.wikipedia.org/wiki/Advanced_Audio_Coding) audio format."
    WAV = "wav"
    "[WAV](https://en.wikipedia.org/wiki/WAV) audio format."
    FLAC = "flac"
    "[FLAC](https://en.wikipedia.org/wiki/FLAC) audio format."

AAC = 'aac' class-attribute instance-attribute

AAC audio format.

FLAC = 'flac' class-attribute instance-attribute

FLAC audio format.

MP3 = 'mp3' class-attribute instance-attribute

MP3 audio format.

OPUS = 'ogg_opus' class-attribute instance-attribute

OGG Opus audio format.

VORBIS = 'ogg_vorbis' class-attribute instance-attribute

OGG Vorbis audio format.

WAV = 'wav' class-attribute instance-attribute

WAV audio format.

FloweryAPIConfig

Bases: BaseModel

Configuration used when making requests to the Flowery API.

Example
from pyflowery import FloweryAPI, FloweryAPIConfig

config = FloweryAPIConfig(
    user_agent = "PyFloweryDocumentation/1.0.0",
    token = "hello world",
    allow_truncation = False,
)

api = FloweryAPI(config=config)

Attributes:

Name Type Description
allow_truncation bool

Whether to allow truncation of text that is too long.

base_url str

The base url for the Flowery API.

interval int

Seconds to wait between each retried request, multiplied by how many attempted requests have been made.

logger Logger

Logger to use for logging messages. One will be automatically created if not provided here.

prepended_user_agent str

Return the user_agent with the PyFlowery module version prepended.

retry_limit int

Number of times to retry a request before giving up.

token str | None

Authorization token to use in HTTP requests. Authorization is only required if you want increased ratelimits.

user_agent str

User-Agent string to use im HTTP requests. Required as of 2.1.0.

Source code in pyflowery/models.py
class FloweryAPIConfig(BaseModel):
    """Configuration used when making requests to the Flowery API.

    Example:
        ```python
        from pyflowery import FloweryAPI, FloweryAPIConfig

        config = FloweryAPIConfig(
            user_agent = "PyFloweryDocumentation/1.0.0",
            token = "hello world",
            allow_truncation = False,
        )

        api = FloweryAPI(config=config)
        ```
    """

    model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True, validate_default=True)

    user_agent: str
    "User-Agent string to use im HTTP requests. Required as of 2.1.0."
    token: str | None = None
    """Authorization token to use in HTTP requests. Authorization is only required if you want increased ratelimits.  
            See the [Flowery API documentation](https://flowery.pw/docs) for more details."""
    base_url: str = "https://api.flowery.pw/v1"
    "The base url for the Flowery API."
    logger: Logger = Field(default_factory=_create_logger)
    "Logger to use for logging messages. One will be automatically created if not provided here."
    allow_truncation: bool = False
    "Whether to allow truncation of text that is too long."
    retry_limit: int = 3
    "Number of times to retry a request before giving up."
    interval: int = 5
    "Seconds to wait between each retried request, multiplied by how many attempted requests have been made."

    @property
    def prepended_user_agent(self) -> str:
        """Return the user_agent with the PyFlowery module version prepended."""
        return f"PyFlowery/{version} {self.user_agent} (Python {sys.version})"

allow_truncation = False class-attribute instance-attribute

Whether to allow truncation of text that is too long.

base_url = 'https://api.flowery.pw/v1' class-attribute instance-attribute

The base url for the Flowery API.

interval = 5 class-attribute instance-attribute

Seconds to wait between each retried request, multiplied by how many attempted requests have been made.

logger = Field(default_factory=_create_logger) class-attribute instance-attribute

Logger to use for logging messages. One will be automatically created if not provided here.

prepended_user_agent property

Return the user_agent with the PyFlowery module version prepended.

retry_limit = 3 class-attribute instance-attribute

Number of times to retry a request before giving up.

token = None class-attribute instance-attribute

Authorization token to use in HTTP requests. Authorization is only required if you want increased ratelimits.
See the Flowery API documentation for more details.

user_agent instance-attribute

User-Agent string to use im HTTP requests. Required as of 2.1.0.

Language

Bases: BaseModel

Language object returned from the Flowery API.

Attributes:

Name Type Description
code str

The code associated with the language.

name str | None

The name associated with the language.

Source code in pyflowery/models.py
class Language(BaseModel):
    """Language object returned from the Flowery API."""

    name: str | None = None
    "The name associated with the language."
    code: str
    "The code associated with the language."

    @override
    def __eq__(self, other: object) -> bool:
        if isinstance(other, Language):
            return True if self.code == other.code else False
        return False

code instance-attribute

The code associated with the language.

name = None class-attribute instance-attribute

The name associated with the language.

TTSResponse

Bases: BaseModel

Object containing data from a TTS query.

Attributes:

Name Type Description
audio_format AudioFormat

What format the data is in.

data bytes

The synthesized TTS data in bytes.

silence timedelta

How long the empty space before the audio starts is. Supported range is 0 - 10 seconds.

speed float

How much the audio is sped up or slowed down. Supported range is 0.5 - 10, in increments of 0.1.

text str

The text used to generate the TTS data.

translate bool

Whether the text was translated into the voice's set language before being synthesized.

voice Voice | None

The voice used to generate the TTS data.

Source code in pyflowery/models.py
class TTSResponse(BaseModel):
    """Object containing data from a TTS query."""

    data: bytes
    "The synthesized TTS data in bytes."
    text: str
    "The text used to generate the TTS data."
    voice: Voice | None = None
    "The voice used to generate the TTS data."
    translate: bool = False
    "Whether the text was translated into the voice's set language before being synthesized."
    silence: timedelta
    "How long the empty space before the audio starts is. Supported range is 0 - 10 seconds."
    audio_format: AudioFormat
    "What format the data is in."
    speed: float = 1.0
    "How much the audio is sped up or slowed down. Supported range is 0.5 - 10, in increments of 0.1."

    @field_validator("speed")
    @classmethod
    def speed_validator(cls, v: object) -> float:
        if not isinstance(v, float):
            raise ValidationError("'speed' is not a float!")
        return v

    @field_validator("silence")
    @classmethod
    def silence_validator(cls, v: object) -> timedelta:
        if v is None:
            v = timedelta(seconds=0)
        if isinstance(v, int):
            v = timedelta(seconds=v)
        if not isinstance(v, timedelta):
            raise ValidationError("'siilence' is not a timedelta!")
        if v.total_seconds() > 10:
            raise ValidationError("'silence' is greater than 10 seconds!")
        if v.total_seconds() < 0:
            raise ValidationError("'silence' is less than 0 seconds!")
        return v

audio_format instance-attribute

What format the data is in.

data instance-attribute

The synthesized TTS data in bytes.

silence instance-attribute

How long the empty space before the audio starts is. Supported range is 0 - 10 seconds.

speed = 1.0 class-attribute instance-attribute

How much the audio is sped up or slowed down. Supported range is 0.5 - 10, in increments of 0.1.

text instance-attribute

The text used to generate the TTS data.

translate = False class-attribute instance-attribute

Whether the text was translated into the voice's set language before being synthesized.

voice = None class-attribute instance-attribute

The voice used to generate the TTS data.

Voice

Bases: BaseModel

Voice object returned from the Flowery API.

Attributes:

Name Type Description
gender str

Gender of the voice.

id str

UUID of the voice.

language Language

Which language the voice is meant to be used for.

name str

Name of the voice.

source str

Which provider the voice comes from.

Source code in pyflowery/models.py
class Voice(BaseModel):
    """Voice object returned from the Flowery API."""

    id: str
    "UUID of the voice."
    name: str
    "Name of the voice."
    gender: str
    "Gender of the voice."
    source: str
    "Which provider the voice comes from."
    language: "Language"
    "Which language the voice is meant to be used for."

gender instance-attribute

Gender of the voice.

id instance-attribute

UUID of the voice.

language instance-attribute

Which language the voice is meant to be used for.

name instance-attribute

Name of the voice.

source instance-attribute

Which provider the voice comes from.