unoserver Documentation

repository·master·Indexed 21 days ago

https://github.com/unoconv/unoserver

A high-performance document conversion service that uses LibreOffice in listener mode to maintain a persistent instance, reducing CPU overhead and increasing throughput. It includes a server, the unoconvert client for file transformations, unocompare for document comparison, and unoping for health checks. Version 3.8.dev0.

Tokens
6.8K
Snippets
21
Records
28
Agent score
76%

What's inside unoserver

  1. How unoserver works: Listener mode vs Headless mode

    master

    Standard LibreOffice conversion (e.g., libreoffice --headless --convert-to pdf ...) loads LibreOffice into memory, performs the conversion, and then exits. This causes high CPU overhead when converting many documents because the software must be reloaded for every file.

    unoserver solves this by using LibreOffice's listener mode. The unoserver command starts a listener on a specified IP and port. This allows the software to stay loaded in memory, accepting multiple conversion requests via a client (unoconverter or unocompare) without exiting and reloading. This can reduce CPU load by 50% to 75% and increase conversion throughput by 2x to 4x.

  2. Compare unoserver with unoconv

    master

    If you are migrating from unoconv to unoserver, be aware of the following architectural and operational changes:

    Operational Differences

    • Client/Server Split: Unlike unoconv, unoserver separates the listener and the client. The unoconverter client requires a running unoserver instance to function; it will not attempt to start a listener automatically.
    • LibreOffice Availability: The unoserver listener does not block you from using LibreOffice as a normal user (opening documents manually), whereas unoconv would block the application.
    • Scaling: unoserver does not include built-in load balancing. To scale on multi-core machines, you must manually run multiple unoserver instances on unique ports using the --port and --uno-port options and implement your own load balancing logic in your client usage.
    • Installation: On Linux, unoserver is easier to install alongside system LibreOffice versions via sudo pip install unoserver because it uses the system Python.

    Technical Differences

    • Compatibility: unoserver only officially supports LibreOffice. It does not rely on hardcoded internal mappings of file types and export filters; instead, it queries LibreOffice directly for this information, improving compatibility across different LibreOffice versions.
    • Runtime: unoserver is a Python 3 rewrite.
  3. Release unoserver to PyPI

    master

    Releases are managed using zest.releaser. Before running the release process, ensure you have a valid .pypirc file configured for uploading packages to PyPI. Use the fullrelease command to start the guided release, packaging, and upload process.

    $ fullrelease
  4. Install unoserver for development

    master

    To set up a development environment for unoserver, clone the repository and create a virtual environment using the --system-site-packages flag. This flag is required to ensure the virtual environment can access the uno library, which relies on a system-level LibreOffice installation using the system Python.

    After creating the environment, install the package in editable mode with the [devenv] extra to include development dependencies.

    $ git clone git@github.com:unoconv/unoserver.git
    $ cd unoserver
    $ virtualenv ve --system-site-packages
    $ ve/bin/pip install -e .[devenv]
  5. Install unoserver on Unix

    master

    To install unoserver on Unix, use pip. Note that unoserver must be installed using the same Python installation that LibreOffice uses to ensure the unoserver command can access the necessary LibreOffice libraries.

    If you have a standard system installation:

    sudo -H pip install unoserver

    If you have multiple LibreOffice versions or a specific LibreOffice distribution, you must run pip using that specific Python executable:

    sudo -H /full/path/to/python -m pip install unoserver

    To find all Python installations that have the relevant LibreOffice libraries installed, you can use the find_uno.py script:

    wget -O find_uno.py https://gist.githubusercontent.com/regebro/036da022dc7d5241a0ee97efdf1458eb/raw/find_uno.py
    python3 find_uno.py
    sudo -H pip install unoserver
  6. Install unoserver in a virtualenv

    master

    If you are using the system Python for your virtual environment, you must include the --system-site-packages flag so the environment can access the LibreOffice libraries installed on the system.

    virtualenv --python=/usr/bin/python3 --system-site-packages virtenv
    virtenv/bin/pip install unoserver
    virtualenv --python=/usr/bin/python3 --system-site-packages virtenv
    virtenv/bin/pip install unoserver
  7. Convert documents with unoconvert

    master

    Use unoconvert to transform files using a running unoserver. You can pass specific filter options to control the output format.

    Set PNG dimensions:

    unoconvert infile.odt outfile.png --filter-options PixelWidth=640 --filter-options PixelHeight=480

    Set CSV output options:

    unoconvert infile.xlsx outfile.csv --filter-options "59,34,76,1"

    Export HTML with embedded images:

    unoconvert infile.odt outfile.html --filter-options EmbedImages
    unoconvert infile.odt outfile.png --filter-options PixelWidth=640 --filter-options PixelHeight=480
  8. Check server status with unoping

    master

    Use unoping to verify if a unoserver instance is up and running. It will print the versions of the server components.

    unoping [-h] [-v] [--host HOST] [--port PORT] [--protocol {http,https}] [--verbose | --quiet] [-f LOGFILE]
    OptionDescription
    --hostThe host used by the server (default: 127.0.0.1)
    --portThe port used by the server (default: 2003)
    --protocolProtocol to connect to the server (default: http)
    --host-location{auto,remote,local}. Determines if files are sent as paths or binary data
    -v, --versionDisplay version and exit
    -f, --logfileWrite logs to a file (defaults to stderr)
    unoping [-h] [-v] [--host HOST] [--port PORT] [--protocol {http,https}] [--verbose | --quiet] [-f LOGFILE]
  9. Compare two documents with unocompare

    master

    The unocompare command connects to a running unoserver to compare two documents and output the result.

    unocompare [-h] [-v] [--file-type FILE_TYPE] [--host HOST] [--port PORT] [--protocol {http, https}] [--host-location {auto,remote,local}] [-f/--logfile logfile] oldfile newfile outfile
    ArgumentDescription
    oldfilePath to the older file (use - for stdin)
    newfilePath to the newer file (use - for stdin)
    outfilePath to the result comparison file (use - for stdout)
    --file-typeThe file type/extension of the result (ex: pdf). Required when using stdout
    --hostThe host used by the server (default: 127.0.0.1)
    --portThe port used by the server (default: 2003)
    --protocolProtocol to connect to the server (default: http)
    --host-location{auto,remote,local}. Determines if files are sent as paths or binary data
    -f, --logfileWrite logs to a file (defaults to stderr)
    unocompare [-h] [-v] [--file-type FILE_TYPE] [--host HOST] [--port PORT] [--protocol {http, https}] [--host-location {auto,remote,local}] [-f/--logfile logfile] oldfile newfile outfile
  10. Reference: unoconvert CLI options

    master

    The unoconvert command connects to a running unoserver to convert documents.

    unoconvert [-h] [-v] [--convert-to CONVERT_TO] [--input-filter INPUT_FILTER] [--output-filter OUTPUT_FILTER] [--filter-option FILTER_OPTIONS] [--update-index] [--dont-update-index] [--host HOST] [--port PORT] [--host-location {auto,remote,local}] [--protocol {http, https}] [-f/--logfile logfile] infile outfile
    OptionDescription
    infilePath to the file to be converted (use - for stdin)
    outfilePath to the converted file (use - for stdout)
    --convert-toThe file type/extension of the output file (ex: pdf). Required when using stdout
    --input-filterThe LibreOffice input filter to use (ex: writer8), if autodetect fails
    --output-filterThe export filter to use. Selected automatically if not specified
    --filter-optionPass an option for the export filter in name=value format or comma-separated list. Can be repeated
    --hostThe host used by the server (default: 127.0.0.1)
    --portThe port used by the server (default: 2003)
    --protocolProtocol to connect to the server (default: http)
    --host-location{auto,remote,local}. local sends paths; remote sends binary data. auto uses paths for 127.0.0.1/localhost and binary for others
    -v, --versionDisplay version and exit
    -f, --logfileWrite logs to a file (defaults to stderr)
    --verboseIncrease informational output to logs
    --quietOnly output errors and warnings
    unoconvert [-h] [-v] [--convert-to CONVERT_TO] [--input-filter INPUT_FILTER] [--output-filter OUTPUT_FILTER] [--filter-option FILTER_OPTIONS] [--update-index] [--dont-update-index] [--host HOST] [--port PORT] [--host-location {auto,remote,local}] [--protocol {http, https}] [-f/--logfile logfile] infile outfile
  11. Reference: unoserver CLI options

    master

    The unoserver command starts the listener. It can also be run as a module using python3 -m unoserver.server with the same arguments.

    unoserver [-h] [-v] [--interface INTERFACE] [--uno-interface UNO_INTERFACE] [--port PORT] [--uno-port UNO_PORT] [--daemon] [--executable EXECUTABLE] [--user-installation USER_INSTALLATION] [-p/--libreoffice-pid-file LIBREOFFICE_PID_FILE] [--conversion-timeout CONVERSION_TIMEOUT] [--stop-after STOP_AFTER] [--temp-dir TEMP_DIR] [--verbose] [--quiet] [-f/--logfile logfile]
    OptionDescription
    -v, --versionDisplay version and exit
    --interfaceThe interface used by the XMLRPC server (default: 127.0.0.1)
    --portThe port used by the XMLRPC server (default: 2003)
    --uno-interfaceThe interface used by the LibreOffice server (default: 127.0.0.1)
    --uno-portThe port used by the LibreOffice server (default: 2002)
    --daemonDaemonize the server
    --executableThe path to the LibreOffice executable
    --user-installationThe path to the LibreOffice user profile (defaults to a dynamically created temporary directory)
    -p, --libreoffice-pid-fileWrite the Libreoffice PID to this file. If in daemon mode, the file is not deleted on exit
    --conversion-timeoutTerminate Libreoffice and exit if a conversion does not complete in the given time (seconds)
    --stop-afterTerminate Libreoffice and exit after the given number of requests
    --temp-dirThe directory to use for temporary files
    --verboseAdd debug information as output
    --quietOnly output errors and warnings
    -f, --logfileWrite logs to a file (defaults to stderr)
    unoserver [-h] [-v] [--interface INTERFACE] [--uno-interface UNO_INTERFACE] [--port PORT] [--uno-port UNO_PORT] [--daemon] [--executable EXECUTABLE] [--user-installation USER_INSTALLATION] [-p/--libreoffice-pid-file LIBREOFFICE_PID_FILE] [--conversion-timeout CONVERSION_TIMEOUT] [--stop-after STOP_AFTER] [--temp-dir TEMP_DIR] [--verbose] [--quiet] [-f/--logfile logfile]