Connect by JBRH Open Connect

Python in Connect

Python is the one language on Connect's server side. The web application, the realtime voice worker, every test suite and almost every operations tool are Python. The production host runs Python 3.12 in a virtual environment at /opt/connect/venv, and the dependencies come from the repository's requirements files.

Status
Reference What this means
Audience
both, developer
Last verified
Product version
6.3.2

What it is#

Python is a general-purpose programming language created by Guido van Rossum and first released in 1991. The reference implementation, CPython, is maintained by the core developers under the Python Software Foundation. A new feature release ships each year, and each release receives about five years of support.

Python suits Connect because nearly every provider Connect talks to publishes a Python SDK or a plain HTTP API: AWS, Google, LiveKit, payment gateways and carriers. Its asyncio model lets one process hold many slow network conversations at once.

Category
Programming language and runtime
Implementation
CPython
Version on the host
3.12, installed as python3.12-venv by ops/aws/bootstrap-host.sh
Official site
python.org

Where Connect uses it#

Place in ConnectWhat it does there
backend/app/The web application: every route, model and background job
backend/voice_worker/The realtime voice worker, run as the connect-voice service
tools/Every regression suite, the docs builder, the gates and the release tooling
ops/Host scripts for mail health, backups and the IMAP backup; most host scripts are shell

How it connects#

  1. requirements*.txt names the packages
  2. The host's venv installs them under /opt/connect/venv
  3. systemd starts uvicorn and python -m backend.voice_worker.agent from that venv
  4. Both processes read the same .env and reach the same PostgreSQL

Benefits and limits#

What it gives Connect:

  • One language from the database query to the deploy check, so a reader follows a feature without changing mental models.
  • Mature SDKs for every provider Connect uses, plus asyncio for concurrent network work.
  • The standard library covers hmac, hashlib, zoneinfo, email and json. Webhook signatures and MIME parsing need no extra dependency.

Where it stops, and what Connect does about it:

  • The global interpreter lock means one process runs Python code on one core at a time. The voice worker is a separate process for this reason, so a busy web request cannot stall an audio frame.
  • CPU-heavy work is slow in pure Python. Connect pushes aggregation into PostgreSQL rather than looping over rows (see query cost).
  • Windows lacks a system time-zone database, so tzdata is a declared dependency (see the locale libraries).

Security and privacy#

  • Services run as the unprivileged user connect with NoNewPrivileges=true.
  • Dependencies are installed from the requirements files, and bandit scans the code in the static gate (development tools).
  • Secrets come from the environment and are never written into the code or these pages.

Licence, cost and versions#

QuestionAnswer
LicencePython Software Foundation License (permissive; GPL-compatible)
CostNone for the language. The cost is the server it runs on (AWS hosting)
Version3.12 on the host. Development checkouts may run a newer 3.x, and the code avoids syntax newer than 3.12
CompatibilityEvery package floor in requirements.txt supports 3.12

Troubleshooting#

ModuleNotFoundError after a release
A new dependency is in requirements.txt but was not installed into /opt/connect/venv. The release script installs requirements, so a manual copy that skipped it is the usual cause.
A time zone such as Asia/Kolkata is not found
The tzdata package is missing on a system without its own zone database.
Odd characters in logs on Windows
The services set PYTHONIOENCODING=utf-8, and local tools should open files with encoding="utf-8".

Official references#

Questions#

Why not Node.js or Go for the server?

The provider SDKs Connect depends on, the data work and the test tooling are strongest in Python, and one language keeps the team's context in one place. The browser side is JavaScript, because that is what browsers run.

Which Python version should a developer use locally?

3.12 matches the host. A newer 3.x works for the suites, but avoid language features newer than 3.12, because the host will refuse to import them.