Readme and model fixes

main
Estelle Poulin 11 months ago
parent a4b4a4c72b
commit fafea87b7d

@ -0,0 +1,88 @@
# Async Python Client to The RTEX API Server
## Installation
```bash
pip install rtex
```
## Usage
The API surface of Rtex is spartan so this is basically the whole thing.
```python
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
```python
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?
```python
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.
```python
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`.
```python
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
)
```

@ -1 +1 @@
__version__ = "0.0.1"
__version__ = "0.0.2"

@ -144,12 +144,18 @@ class AsyncRtexClient:
self,
code: str,
format: RenderFormat = "png",
documentclass: str = "minimal",
quality: Optional[RenderQuality] = None,
density: Optional[RenderDensity] = None,
):
final_doc = rf"\({code}\)"
res = await self.create_render(
code=final_doc,
format=format,
documentclass=documentclass,
quality=quality,
density=density,
)
if res.status == "error":

@ -3,7 +3,7 @@ from typing import Annotated, Literal, Optional, Union
from pydantic import BaseModel, Field, conint
RenderFormat = Literal["png", "jpg", "pdf"]
RenderQuality = Annotated[int, conint(ge=0, le=100)]
RenderQuality = Annotated[int, conint(gt=0, le=100)]
RenderDensity = int

Loading…
Cancel
Save