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

## Self Hosting

For privacy reasons or for those needing to use browser-based sketches without "full" internet access (like for offline Progressive Web Apps or behind firewalls), you can also download a copy of the required files for full self-hosting. By default, these assume that they are located in a directory called "third_party" at the root of the server and can be included like so:

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

            <!-- You may need to change these paths to pyscript files. -->
            <link rel="stylesheet" href="/third_party/core.css">
            <script type="module" src="/third_party/core.js"></script>
        </head>
        <body>
            <py-config>
            {
                "packages": ["/third_party/sketching-0.0.8-py3-none-any.whl"]
            }
            </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)

If you are hosting these files elsewhere, change "third_party" above to the correct path and also update "core.js" using the a simple string replacement like in this Python script:

    with open('core.js') as f:
        original_content = f.read()

    new_content = original_content.replace('/third_party/', 'YOUR_NEW_PATH')

    with open('core.js', 'w') as f:
        f.write(new_content)

Note that zip file use 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. Also, please see the underlying sources as, under certain configurations like use of pypi packages, this "self-hosted" version may still caues external network traffic. Finally, for privacy-sensitive use cases, consider using a browser's web inspector to look for traffic to confirm other servers beyond those intended one are not contacted.
{% endblock %}