Urgent.News

What's breaking now, across thousands of outlets.

AI

Building a gemini server in python

The Gemini protocol emerged seven years ago as an alternative to the modern web, focusing on providing value to independent content creators without the distractions of the main web. It functions with a stripped-down format called gemtext, similar to markdown, and operates on a non-standard port (1965) to avoid confusion with existing web services.

To set up a Gemini server in Python, you first create a TCP socket to listen on the appropriate port, using low-level APIs to bind the socket to '0.0.0.0' for listening on all network interfaces. After running the server, you can test it using a TCP client like telnet or nc to check if it correctly responds with 'Hello' to requests.

Gemini requests are simple, consisting of an absolute URL under 1024 bytes. The server responds with 'Hello' for the path '/hello' and '/goodbye' for the path '/goodbye'. For a fully functional Gemini server, it must use TLS encryption. Similar to the web, Gemini servers can use self-signed certificates with a "Trust on first use" (TOFU) policy.

Generating a self-signed certificate using OpenSSL is straightforward and allows you to provide a unique TLS certificate for your server. By configuring your Python server to use this certificate, you enable encryption for secure Gemini communication.

To extend your server, you can add routes to handle user input. Gemini servers support status 10 to indicate that user input is required, prompting the client for a single text field in the same URI. Implementing a route to echo back user input demonstrates this functionality. For enhanced security, Gemini supports mutual TLS (mTLS), allowing both server and client to present their own TLS certificates, enabling client identification based on certificate authenticity.

This process involves generating certificates for both parties and configuring your Python server to verify the client's certificate. Once configured, your Gemini server can securely serve content and accept user input, offering a minimalist yet robust alternative to the modern web.

Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at willmunn.xyz →

More in AI

More from Monday 2 November →