{% extends "base.html" %} {% block main %}

## Deploying

Sketching has different approaches for deployment depending on where you are going.

### Desktop

You have some options for deployment of Python stand-alone executables which offer users programs that can be used without a system-wide Python through file formats like exe, dmg, etc. Consider reviewing cx_Freeze and PyInstaller. Here is an example setup.py for cx_Freeze adapted from their documentation:

    import sys
    import cx_Freeze

    # Dependencies are automatically detected, but it might need fine tuning.
    build_exe_options = {
        'zip_include_packages': ['sketching', 'pygame'],
        'include_files': ['reference.png']
    }

    # base='Win32GUI' should be used only for Windows GUI app
    base = 'Win32GUI' if sys.platform == 'win32' else None

    cx_Freeze.setup(
        name='sketch',
        version='0.1',
        description='Sketch export',
        options={'build_exe': build_exe_options},
        executables=[cx_Freeze.Executable('sketch.py', base=base)]
    )

This can be built with:

    python setup.py build

Note that this example includes an image which is bundled with the executable. For more details, see cx_Freeze documentation.

### Web

Sketching.py can go anywhere your web development can take you. Unlike desktop Python, requirements are crafted directly in the web document itself. If you haven't written HTML before, we suggest the Mozilla Developer Network's introduction. With that, here's a minimal example:

    <!doctype html>
    <html>
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width,initial-scale=1.0">

            <!-- PyScript -->
            <link rel="stylesheet" href="https://pyscript.net/releases/2023.11.2/core.css">
            <script type="module" src="https://pyscript.net/releases/2023.11.2/core.js"></script>
        </head>
        <body>
            <py-config>
            {
                "packages": ["sketching==0.0.8"]
            }
            </py-config>

            <!-- You may need to change this ID to match your code. -->
            <div id="sketch-load-message">Loading...</div>
            <canvas id="sketch-canvas"></canvas>

            <!-- You can link the script as shown below or use py-script to inline -->
            <script type="py" src="main.py"></script>
        </body>
    </html>

This will work with the defaults:

    sketch = sketching.Sketch2DWeb(width, height)

However, if you change the IDs of the canvas and loading div, you may need to change you initialization code:

    width = 400
    height = 500
    canvas_id = 'different-canvas'
    loading_id = 'different-loading-id'
    sketch = sketching.Sketch2DWeb(width, height, canvas_id, loading_id)

Regardless, this easiest approach assumes that you are using the content distribution network (CDN) from PyScript which means that traffic will access outside services beyond the website where the sketch itself is located. For an alternative, see self-hosting information. Note that the CDN uses sources from other open source projects including those from the PyScript project subject to their permissive license. For more information, see the PyScript user guide.

### Server

The static renderer only requires Pillow and Sketching.py where the later is a pure-Python distribution. For more details on how to install Pillow, see the Pillow installation documentation. Note that Sketching.py will work with the libraries installed so will not necessarily raise an error that Pillow is missing.
{% endblock %}