Posts

Showing posts with the label Python Flask

Deploy a Python Flask App for Free on Railway (No Credit Card)

Image
  Here’s a detailed step-by-step guide to deploying a Python Flask app on Railway(Click here) : Step 1: Prepare Your Flask App Ensure your Flask app meets these requirements: Basic Flask App Structure Your app.py (or main script) should include this: from flask import Flask import os app = Flask(__name__) @app.route("/") def home () : return "Hello, Railway!" if __name__ == "__main__" : port = int(os.environ.get( "PORT" , 5000 )) # Railway requires listening on this port app.run(host= "0.0.0.0" , port=port) Requirements File Create a requirements.txt file listing all dependencies. Use this command: pip freeze > requirements.txt Procfile Create a Procfile (no file extension) in the root directory: we b: python app. py Replace app.py with the filename of your main Flask script if necessary. Step 2: Set Up a Git Repository Railway uses Git for deployment. Initialize a Git repository for your project: gi...

AWS S3 + Python Flask - File Upload, Download, List, and Delete Example

Image
To implement file upload, list, download, and delete operations for AWS S3 in a Flask app, you can follow the steps below. This example will: Upload files to an S3 bucket. List files available in the S3 bucket. Download files from the S3 bucket. Delete files from the S3 bucket. Step 1: Install Required Libraries Make sure you have Flask and boto3 installed. pip install Flask boto3 Step 2: AWS S3 Configuration You will need AWS credentials and an S3 bucket. You can either: Set the AWS credentials as environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY). Or use the default AWS credentials file located at ~/.aws/credentials. Step 3: Flask Application with File Upload, List, Download, and Delete Here's a simple Flask app that integrates with AWS S3 for file upload, listing, downloading, and deleting. from flask import Flask, request, send_file, jsonify import boto3 from botocore.exceptions import NoCredentialsError import os # Initialize Flask app app = ...