π Deployment GuideΒΆ
Deploying your Duck web application is simple, fast, and beginner-friendly β no need for extra tools like NGINX, Daphne, or other ASGI/WSGI gateways.
π§ PrerequisitesΒΆ
Note
Required Python version: >= 3.10 (recommended: 3.12+)
Recommended OS: Linux (many Duck features rely on Linux system features).
Steps to Deploy Your Duck ApplicationΒΆ
1. Create and Activate a Virtual EnvironmentΒΆ
A virtual environment (venv) helps keep your project dependencies isolated and clean.
Run these commands in your project directory:
python3.12 -m venv .venv # Or python3.10 upto latest python version
Then activate it:
source .venv/bin/activate
You should now see something like:
$ (venv)
After activation, install your dependencies using pip.
Note
β
Use Python 3.12 or later for best performance and compatibility.
β
On Linux, you can install a modern Python version using sudo apt install python3.12 or pyenv.
π« Avoid misusing sudo as this grants you admin rights.
2. Run Duck as RootΒΆ
When running your Duck app on a VPS or remote server, you may want to use port 80 (HTTP) or 443 (HTTPS).
These ports require admin privileges, so a normal command like duck runserver wonβt work directly.
To solve this, use the following command that gives Duck the necessary permissions safely:
sudo $(python -c "import sys; print(sys.executable)") -m duck runserver ... # Or run web/main.py
π‘ Explanation:
This command runs Duck using the exact Python executable you installed it with, avoiding common issues like
ModuleNotFoundError: No module named 'duck'.
3. Obtain an SSL CertificateΒΆ
Duck provides built-in, free SSL support via Letβs Encrypt.
Follow the Free SSL Certificate Guide for step-by-step instructions.
Once configured, Duck can auto-renew certificates without manual action.
4. Enable HTTPS & HTTP/2ΒΆ
After obtaining your SSL certificate, enable HTTPS and HTTP/2 for secure and faster connections.
See HTTPS and HTTP/2 setup guide for full configuration details.
5. Redirect All HTTP Traffic to HTTPSΒΆ
Ensure users visiting your site via http:// are automatically redirected to https://.
In your settings.py, enable HTTPS redirection:
FORCE_HTTPS = True
FORCE_HTTPS_BIND_PORT = 80 # Optional: specify the port to redirect from
Duck uses a built-in MicroApp called HttpsRedirectMicroApp to handle redirects efficiently.
See MicroApp documentation for customization details.
6. Run the App as a Background ServiceΒΆ
Warning
The duck service command works only on Linux.
To keep your app running even after closing your terminal, run it as a background service:
$ (venv) sudo $(python -c "import sys; print(sys.executable)") -m duck service autorun # or just use duck service autorun for less privileges
This command will:
Automatically create a systemd service for your app
Save it under your systemβs service directory
Start it instantly
Note
Do not forget to customize
SYSTEMD_EXEC_COMMANDinsettings.py, this is the command that will be run bysystemd. By default the command points tof"{sys.executable} web/main.py". Usually, itβs only necessary to configure this if you are explicitly usingduck runserverinstead ofweb/main.py.Do not forget to activate your virtual environment where you installed
Duck.
For advanced options, see Service Management.
π‘ Tip: On non-Linux systems, you can use tools like systemd, supervisord, or pm2 as alternatives.
π Notes & Best PracticesΒΆ
Note
It is strongly recommended to use the asynchronous implementation (ASGI) rather than the synchronous (WSGI) interface in production environments. ASGI provides superior scalability and efficiency by leveraging a non-blocking event loop, making it better suited for modern high-concurrency workloads.
Before going live, make sure your application is optimized and secure:
Make sure you set the app domain:
python3 -m duck runserver -d mysite.com # Or just use your IP if no domainOr provide it to
Appinstance:app = App(domain="mysite.com") # Or your IP if no domainBut also, donβt forget to set it in
SYSTEMD_EXEC_COMMANDinsettings.pyif you are explicilty usingduck runserverinstead ofweb/main.py.Use workers:
# From command line duck runserver --workers auto # Or just specify number of workers.# From web/main.py app = App(..., workers=os.cpu_count() or 4, force_https_workers=2)The above examples runs the server using worker processes, thus, utilizing the available CPU cores. This improves overall performance. As this brings more benefits, it also uses more system resources as some background threads will be restarted in each process.
Turn off debug mode:
DEBUG = FalseSilence unnecessary logs:
SILENT = True LOG_TO_FILE = TrueReduce log verbosity (optional):
VERBOSE_LOGGING = FalseMonitor your application:
duck monitor # Auto-detect all processes starting with duckor explicitly provide target processes:
duck monitor --duck-process "duck*" # Matches all processes starting with duckor explicitly provide target process IDs:
duck monitor --pid <process_id>Open required ports:
Make sure ports 80 (HTTP), 443 (HTTPS) and other ports like 465 (SMTPS port for sending and receiving emails) are open in your VPS or hosting firewall settings.
π Youβre Done!ΒΆ
Your Duck web app is now fully deployed and production-ready.
Keep your environment updated, monitor performance, and enjoy a smooth deployment process β all powered by Duck.