Skip to main content

*Unofficial* client for the Rtex API server

Project description

Async Python Client to The RTEX API Server

Installation

pip install rtex

Usage

The API surface of Rtex is spartan so this is basically the whole thing.

import asyncio

from rtex.client import AsyncRtexClient

async def amain():
  async with AsyncRtexClient() as rtex:
    res = rtex.create_render("\(x^2 + x - 1\)")

    if res.status == "success":
      with open("equation.png") as output_fd:
        await res.save_render(
          res.filename,
          output_fd
        )

def main():
  asyncio.run(amain())

if __name__ == "__main__":
  main()

No Thoughts, Just Render

async def amain():
  async with AsyncRtexClient() as rtex:
    buf = await rtex.render_math("e^x + 1")

    # `buf` now contains the bytes of the PNG

Do I look like I know what a Jay-Peg is?

async def amain():
  async with AsyncRtexClient() as rtex:
    # The render methods accept a format parameter.
    # Supported values are "png", "jpg" and "pdf"
    buf = await rtex.render_math("e^x + 1", format="jpg")

Self-Hoster

Set the environment variable RTEX_API_HOST or do the following.

async def amain():
  async with AsyncRtexClient(api_host="https://myserver.ru") as rtex:
    buf = await rtex.render_math("e^x + 1")

I Can Tell By The Pixels

quality in Rtex speak is an abstract notion of compression for the given format where 100 is the least compressed and 0 is the most. At the time of writing the default is 85.

density in Rtex speak is how much to sample the rendered PDF when generating an image. This has no effect on the "pdf" format. At the time of writing the default is 200.

async def amain():
  async with AsyncRtexClient(api_host="https://myserver.ru") as rtex:
    needs_more_jpeg = await rtex.render_math(
      "e^x + 1",
      density=50,
      quality=1
    )

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

rtex-0.0.6.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

rtex-0.0.6-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file rtex-0.0.6.tar.gz.

File metadata

  • Download URL: rtex-0.0.6.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rtex-0.0.6.tar.gz
Algorithm Hash digest
SHA256 6d2a83807ec33777ed0666cc648c6ec4617b93092f379e4c81792ba21abef89f
MD5 1047c5bdc688d1eadbcc46f668fe2271
BLAKE2b-256 989d80b847f808c022892bf78487272f3b3169e0c8c3bef754163d0cd3115586

See more details on using hashes here.

File details

Details for the file rtex-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: rtex-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rtex-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 64fbd1828e59dc0e0630f3644b3589e5f07e149b2a10b5ac2eef9b6d9d7d2479
MD5 962327ef653746d221d680bbe74f4bdc
BLAKE2b-256 d3334f64d6a2d3c5fd0326270aea4a272b7aa5df409d5bec78ff0e0e266b96e3

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