### Local Server Execution and Request Examples Source: https://context7.com/digitalocean/sample-python/llms.txt Demonstrates how to start the Python server locally and make sample curl requests to test its responses for different paths and query parameters. ```bash # Start the server locally PORT=8080 python server.py # Make a request to the root path curl http://localhost:8080/ # Output: Hello! you requested / # Make a request to a custom path curl http://localhost:8080/api/users # Output: Hello! you requested /api/users # Make a request with query parameters curl "http://localhost:8080/search?q=python" # Output: Hello! you requested /search?q=python ``` -------------------------------- ### Procfile for Process Declaration Source: https://context7.com/digitalocean/sample-python/llms.txt Declares the 'web' process type, specifying the command to run the Python server application. This is used by DigitalOcean App Platform to start the service. ```bash # Procfile - Process type declaration for App Platform web: python server.py ``` -------------------------------- ### Python HTTP Server Handler Source: https://context7.com/digitalocean/sample-python/llms.txt Defines a custom request handler that extends Python's built-in HTTP handler to respond to GET requests. It reads the port from the PORT environment variable. ```python import os import http.server import socketserver from http import HTTPStatus class Handler(http.server.SimpleHTTPRequestHandler): def do_GET(self): self.send_response(HTTPStatus.OK) self.end_headers() msg = 'Hello! you requested %s' % (self.path) self.wfile.write(msg.encode()) # Start the server on the port specified by PORT environment variable (default: 80) port = int(os.getenv('PORT', 80)) print('Listening on port %s' % (port)) httpd = socketserver.TCPServer(('', port), Handler) httpd.serve_forever() ``` -------------------------------- ### Deploy Sample Python App to DigitalOcean Source: https://github.com/digitalocean/sample-python/blob/main/README.md Click this button to deploy the sample Python app to DigitalOcean App Platform. This action may disable automatic re-deployments if the repository is used directly. ```markdown [![Deploy to DigitalOcean](https://www.deploytodo.com/do-btn-blue.svg)](https://cloud.digitalocean.com/apps/new?repo=https://github.com/digitalocean/sample-python/tree/main) ``` -------------------------------- ### Deploying with DigitalOcean CLI Source: https://context7.com/digitalocean/sample-python/llms.txt Provides commands to deploy the application to DigitalOcean App Platform using the doctl CLI or by forking the repository. ```bash # Deploy using DigitalOcean CLI (doctl) doctl apps create --spec .do/app.yaml # Or deploy by forking the repository and connecting via the DigitalOcean dashboard # Visit: https://cloud.digitalocean.com/apps/new?repo=https://github.com/digitalocean/sample-python/tree/main ``` -------------------------------- ### DigitalOcean App Platform Specification Source: https://context7.com/digitalocean/sample-python/llms.txt The App Platform specification file defines the service, repository, and deployment settings for the Python application on DigitalOcean. ```yaml # .do/app.yaml - App Platform specification name: sample-python services: - environment_slug: python github: branch: main deploy_on_push: true repo: digitalocean/sample-python name: sample-python ``` -------------------------------- ### Edit server.py for a Custom Greeting Source: https://github.com/digitalocean/sample-python/blob/main/README.md Modify the `server.py` file to change the default greeting message. This change can then be committed and deployed to see the updated application. ```python edit `server.py` and replace "Hello!" on line 12 with a different greeting ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.