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.7.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.7-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rtex-0.0.7.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.7.tar.gz
Algorithm Hash digest
SHA256 41a7aa1185419d188b0c935bfc09b05e82aab32ffff8e1312333d1969a456424
MD5 28281262f56013d71eb18aba593e5f38
BLAKE2b-256 1c4fc86fdcabcec74b11c57e85abe4db026cea5b64c24dc842c444888222bb99

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rtex-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 5.5 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d64137eff4475e400fd6e66f8c31cdde6826ecbc1ce2a1795bddefac450be1ba
MD5 cfad8a37c4a4c96827ff2f045d06c920
BLAKE2b-256 df63718c263623e9c59258a32c8ec7173e4b351ea45964759f90b000a6c7283a

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