Skip to content

Repository files navigation

UI for GroupDocs.Viewer for Python via .NET

PyPI Python

GroupDocs.Viewer UI

A web UI for groupdocs-viewer-net — view 190+ document and image formats in a browser. Mount inside an existing FastAPI / Flask / Django app, or run standalone via the bundled CLI.

The frontend is the same battle-tested Angular SPA from the GroupDocs.Viewer for .NET UI project (26.10.0, on Angular 22), vendored into this package — one pip install and you're done.

Install

pip install groupdocs-viewer-net-ui

Optional cloud-storage / cache backends:

pip install "groupdocs-viewer-net-ui[s3]"      # S3FileStorage
pip install "groupdocs-viewer-net-ui[azure]"   # AzureBlobFileStorage
pip install "groupdocs-viewer-net-ui[redis]"   # RedisCache
pip install "groupdocs-viewer-net-ui[all]"

Run it

CLI (zero config)

groupdocs-viewer-ui serve --files ./documents --cache ./.viewer-cache
# → http://127.0.0.1:8080/viewer/

Docker

docker compose up
# Drop documents into ./documents on the host

In code

from groupdocs_viewer_ui import Config, create_app
from groupdocs_viewer_ui.cache.local import LocalFileCache
from groupdocs_viewer_ui.storage.local import LocalFileStorage
from groupdocs_viewer_ui.viewer.selfhost import SelfHostViewer

storage = LocalFileStorage("./Files")
app = create_app(
    Config(),
    storage=storage,
    cache=LocalFileCache("./Cache"),
    viewer=SelfHostViewer(storage=storage),
)
# Run with: uvicorn myapp:app

create_app() returns a Starlette ASGI app — mount it under FastAPI directly, or bridge to Flask/Django with a2wsgi. See examples/ for runnable patterns.

Configure

Config() accepts knobs for rendering mode, preload count, initial zoom, UI toggles (header, toolbar, thumbnails, search, print, etc.), localization, branding, and routing. See AGENTS.md for the full field reference.

Config(
    rendering_mode="html",        # or "image"
    preload_pages=3,
    initial_zoom="Fit Page",      # or "Fit Width", "Fit Height", "100%", "75%", etc.
    enable_thumbnails=True,
    enable_rotate=True,           # rotate buttons in the toolbar
    default_theme="light",        # or "dark", or "auto" to follow the operating system
    ui_title="My Document Viewer",
    custom_css="<style>:root { --c-bg-brand: #0d9488; }</style>",
)

The toolbar's theme switcher (enable_theme_switcher) lets each user pick light or dark; the choice is kept in the browser. Dark-theme colors in custom_css go under :root[data-theme="dark"]. Uploads (enable_file_upload) are capped at max_upload_size_bytes, 30 MB by default, and an upload by URL only fetches from public internet addresses.

Storage backends

Built-in: LocalFileStorage, S3FileStorage ([s3] extra), AzureBlobFileStorage ([azure] extra). Implement the FileStorage protocol for anything else — three async methods. See examples/05_custom_storage/ for a SQLite-backed example.

Cache backends

Built-in: InMemoryCache, LocalFileCache, RedisCache ([redis] extra). When you supply both viewer and cache to create_app(), the viewer is auto-wrapped in a CachingViewer decorator — no manual composition required. Implement the FileCache protocol for custom backends. See examples/06_custom_cache/ for a TTL wrapper.

Thumbnails are rendered when the browser asks for them, and the browser asks for one for every page it shows, even with the thumbnail pane closed.

Render options

SelfHostViewer takes a function per output type, called on the engine's options object before each render: configure_html_view_options, configure_png_view_options and configure_pdf_view_options. For example, to optimize the PDFs it renders:

from groupdocs.viewer.options import PdfOptimizationOptions

def optimize_pdf(options):
    optimization = PdfOptimizationOptions()
    optimization.optimize_spreadsheets = True
    options.pdf_optimization_options = optimization

viewer = SelfHostViewer(storage=storage, configure_pdf_view_options=optimize_pdf)

The cache does not know about these options: clear it after changing them.

Authentication

from starlette.exceptions import HTTPException

async def require_session(request):
    if request.cookies.get("session") not in VALID_SESSIONS:
        raise HTTPException(status_code=401, detail="Login required")

app = create_app(..., auth_check=require_session)

The check runs before every /viewer-api/* request. /health, the SPA, and static assets are deliberately not guarded — wrap the whole app yourself if you need broader scope. Refuse with 401, not 403: the viewer answers a 403 from the API by asking for the document's password. See examples/07_auth/ for session-cookie + bearer-token patterns.

For rate limiting, pair with slowapi or asgi-ratelimit as standard Starlette middleware.

Examples

Path Shows
examples/01_cli_quickstart/ Zero-config CLI demo
examples/02_fastapi_basic/ Mount in FastAPI
examples/03_flask_basic/ Mount in Flask via a2wsgi
examples/04_custom_branding/ Custom logo + CSS
examples/05_custom_storage/ SQLite FileStorage
examples/06_custom_cache/ TTL FileCache decorator
examples/07_auth/ Session cookie + bearer token auth

Linux

groupdocs-viewer-net needs ICU, fonts and fontconfig for rendering (no libgdiplus since 26.9). The bundled Dockerfile installs them; for bare metal:

sudo apt-get install -y libicu-dev libfontconfig1 fontconfig fonts-liberation fonts-dejavu
# MS Project (MPP/MPT/MPX) also needs the Microsoft core fonts (Debian: enable "contrib"):
sudo apt-get install -y ttf-mscorefonts-installer

On Linux/macOS groupdocs-viewer-net runs the cross-platform build of the engine, which renders every format except Photoshop (PSD, PSB), Adobe Illustrator (AI) and OneNote — those are Windows-only. Everything else works on all platforms, including Visio and, since 26.9, Microsoft Project (MPP, MPT, MPX).

Documentation

Development

pip install -e ".[dev]"
pytest                         # 367 passing, 1 skipped by platform (5 e2e tests render a real DOCX)
ruff check src tests
mypy src

License

MIT — see LICENSE.

Support

Releases

Packages

Contributors

Languages