Seamlessly serve your static assets of your Flask app from Amazon S3

Related tags

Flaskflask-s3
Overview

flask-s3

Build Status Coverage Status Analytics PyPI Version

Seamlessly serve the static assets of your Flask app from Amazon S3.

Maintainers

Flask-S3 is maintained by @e-dard, @eriktaubeneck and @SunDwarf.

Installation

Install Flask-S3 via pypi:

pip install flask-s3

Or, install the latest development version:

pip install git+https://github.com/e-dard/flask-s3

Documentation

The latest documentation for Flask-S3 can be found here.

Comments
  • Added support for AWS CloudFront (or any other CDN)

    Added support for AWS CloudFront (or any other CDN)

    This allows you to change the base domain to anything and won't include the S3 bucket name before the url, as it does when changing S3_BUCKET_DOMAIN. I updated the docs (so you'll want to update the readthedocs.org site) and added a test for the feature.

    opened by eriktaubeneck 12
  • Refactor app.config defaults setup

    Refactor app.config defaults setup

    @e-dard Just wanted to get your thoughts on this.

    The basic idea here is that if USE_S3 is unset, then in the case where app.debug is True (and USE_S3_DEBUG is False), we'd simply turn USE_S3 to False. This offers a couple advantages:

    • No need to check app.config on every call of url_for. We simply override it if USE_S3 is True at initialization. I don't think app.config could ever change without restarting the app (and even it it's possible, it's a serious anti-pattern, I think).
    • The application can reference app.config["USE_S3"] as a definitive test as to if files are being served locally or remotely. The use case I have for this is an app that allows users to upload images, which go directly to S3 (they never exist on the web server, except in memory between the upload and the upload to S3). I use the url_for function in S3 to generate those urls still, but then locally/testing I need to upload them to the filesystem. As of now, this requires:
    if app.config['USE_S3'] and (not app.debug or app.config['USE_S3_DEBUG']):
        s3_upload()
    else: # not app.config['USE_S3'] or (app.debug and not app.config['USE_S3_DEBUG'])
        local_upload()
    

    which ideally would simplify to

    if app.config['USE_S3']:
        s3_upload()
    else: # not app.config['USE_S3']
        local_upload()
    
    opened by eriktaubeneck 9
  • Big refactoring code and tests

    Big refactoring code and tests

    • fix #16
    • prepare to be compatible with py3
    • use coverage and coveralls.io
    • using tqdm for print progress coping files (if log level = Info)
    • fix by autopep8

    All existing tests are passed.

    opened by klinkin 8
  • Naming of config variables

    Naming of config variables

    Hey folks, I just added Flask-S3 to a project, and I think the naming of the config variables ought to be changed to be specific to this module; perhaps with a FLASKS3_ prefix (like how the Flask-Security module does it).

    I already have a config var called S3_BUCKET in my project, and now I have S3_BUCKET_NAME.. Which doesn't provide the clearest distinction in the code base.

    Just a thought. Interested to see what you think.

    opened by mafrosis 6
  • socket.error when calling create_all()

    socket.error when calling create_all()

    I was trying to setup flask-s3 for my app but I kept getting a socket.error (either broken pipe or connection reset by peer) when running flask_s3.create_all(app) in a python shell as suggested in the docs. I had already made the bucket and was just trying to upload my static assets.

    The fix appears to be to set the (undocumented) config variable S3_REGION to the region in which you created your bucket. However, this caused an error for me when the create_all() function tried to call conn.create_bucket(bucket_name). By changing this call to a get_bucket() call, I was able to execute create_all() without error.

    bug 
    opened by asib 6
  • Only upload files that have been modified

    Only upload files that have been modified

    I wanted to speed up build/deploy times on our build server so this stores a list of SHA-1 hashes for all files that have been uploaded to S3. Only files with a different/unknown hash are then uploaded.

    Please note that I also changed bucket.make_public call to not be recursive as this takes a long time if you have many files, and all the files will already be set as public by Flask-S3 when they were uploaded previously. It is a bit of a compromise since if you manually added any files to S3 they won't be marked as public but I think that's a fair enough assumption.

    opened by andrewsnowden 5
  • Add the option to use path-style S3 URLs.

    Add the option to use path-style S3 URLs.

    It's sometimes desirable to use path-style URLs over virtual-host-style URLs. For example, a bucket name with a dot in it will trigger invalid SSL certificate errors on some browsers, since S3's *.s3.amazonaws.com certificate only covers single-level subdomains.

    This adds the S3_URL_STYLE setting, which can be one of 'host' or 'path', defaulting to 'host' for compatibility.

    opened by grampajoe 5
  • Add support for setting custom headers for files uploaded to S3

    Add support for setting custom headers for files uploaded to S3

    Today there's only support for setting the Cache-Control header. I've removed the S3_CACHE_CONTROL setting and added S3_HEADERS which supports setting whatever header you want:

    S3_HEADERS = {
        'Expires': 'Thu, 15 Apr 2010 20:00:00 GMT',
        'Cache-Control': 'max-age=86400',
    }
    
    opened by hannseman 5
  • Only possible to use root user

    Only possible to use root user

    I would like to make a user with restricted permissions but permission are reset to 'public-read' on each usage. This removes authorised users and restrictes writing to the account owner.

    To see this behaviour:

    • Create an IAM user with permissions to access the BUCKETNAME
    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": "s3:*",
                "Resource": "arn:aws:s3:::BUCKETNAME"
            }
        ]
    }
    
    • Set the bucket so that any authorised user has all permissions.
    • Run flask-s3
    • Observe to see if authorised users have no permissions on the bucket. it has reset to root write and public read.
    opened by wassname 4
  • Convert readthedocs links for their .org -> .io migration for hosted projects

    Convert readthedocs links for their .org -> .io migration for hosted projects

    As per their blog post of the 27th April ‘Securing subdomains’:

    Starting today, Read the Docs will start hosting projects from subdomains on the domain readthedocs.io, instead of on readthedocs.org. This change addresses some security concerns around site cookies while hosting user generated data on the same domain as our dashboard.

    Test Plan: Manually visited all the links I’ve modified.

    opened by adamchainz 3
  • Latest release 0.2.13 do not defines default values for configuration keys

    Latest release 0.2.13 do not defines default values for configuration keys

    I received an update from pip for Flask-S3 from 0.2.8 to 0.2.13 but there are some strange things going on and I don't think the release should be kept there.

    For example, from the documentation is missing content on the section Flask-S3 Options, and also the code don't have default values for configuration keys (all of them, I kept receiving KeyError: 'FLASKS3_*' until I declared all of them in my config file).

    I just downgraded to 0.2.8 but I think it's best to remove this faulty release, or to fix it.

    Thanks!

    bug cantreproduce 
    opened by dappiu 3
  • docs: Fix a few typos

    docs: Fix a few typos

    There are small typos in:

    • docs/index.rst
    • flask_s3.py
    • test_flask_static.py

    Fixes:

    • Should read separates rather than seperates.
    • Should read relative rather than ralative.
    • Should read overridden rather than overriden.

    Semi-automated pull request generated by https://github.com/timgates42/meticulous/blob/master/docs/NOTE.md

    opened by timgates42 0
  • Can't upload only a single folder in static to S3 - anyone?

    Can't upload only a single folder in static to S3 - anyone?

    Hi,

    When I upload to S3 by using flask_s3.create_all(app), I sometimes want to limit it to only the tailwind css. According to the docs, the filepath_filter_regex variable is supposed to accommodate that. In my static folder I have a gen_tailwind folder, so I would think that using flask_s3.create_all(app,filepath_filter_regex=r'^gen_tailwind') would upload only this folder. However, when I run it, nothing happens, and it doesn't give any return message.

    Anyone know what I am doing wrong?

    opened by kingkong-cmd 0
  • Github code doesn't match with uploaded Pypi version

    Github code doesn't match with uploaded Pypi version

    Current GitHub code doesn't matches with content of Pypi. For example in Pypi version (I downloaded de latest package: 0.3.3) the feature FLASKS3_ENDPOINT_URL is not implemented but in GitHub it works well:

    https://github.com/e-dard/flask-s3/blob/b8c72b40eb38a05135eec36a90f1ee0c96248f72/flask_s3.py#L409

    opened by cr0hn 0
  • Exclude some files

    Exclude some files

    When I deploy to production I'd like to exclude the sourcemap files in my static directory. I'd like a config option to exclude any "*.js.map" files so they aren't ever part of my production deploy to S3.

    Until then, I've put my sourcemaps in a different directory, outside of static, but that needs extra config for webpack and for serving them in Flask.

    opened by bridger 0
Releases(0.2.8)
Owner
Edd Robinson
Engineering at @influxdata. Work on IOx. Storage, indexing, whisky. Not in that order. 🥃 🦀
Edd Robinson
An python flask app with webserver example

python-flask-example-keepalive How it works? Basically its just a python flask webserver which can be used to keep any repl/herokuapp or any other ser

KangersHub 2 Sep 28, 2022
With Flask. Everything in a JSON.

Little Library REST API py 3.10 The only one requeriment it's to have Flask installed. To run this, in ./src/(if you're in PS): $env:FLASK_APP="app

Luis Quiñones Requelme 1 Dec 15, 2021
a flask profiler which watches endpoint calls and tries to make some analysis.

Flask-profiler version: 1.8 Flask-profiler measures endpoints defined in your flask application; and provides you fine-grained report through a web in

Mustafa Atik 718 Dec 20, 2022
iloveflask is a Python library to collect functions that help a flask developer generate reports, config files and repeat code.

I Love Flask iloveflask is a Python library to collect functions that help a flask developer generate reports, config files and repeat code. Installat

2 Dec 29, 2021
Flask RESTful Web services using API to communicate between client and server.

Welcome! Open up two terminals, one for client and for server each Terminal 1 Terminal 2 Now navigate to the CW2_code directory in both like so $ cd C

Sehra Elahi 1 Nov 23, 2021
A flask template with Bootstrap 4, asset bundling+minification with webpack, starter templates, and registration/authentication. For use with cookiecutter.

cookiecutter-flask A Flask template for cookiecutter. (Supports Python ≥ 3.6) See this repo for an example project generated from the most recent vers

4.3k Dec 29, 2022
RestApi_flask_sql.alchemy - Product REST API With Flask & SQL Alchemy

REST API With Flask & SQL Alchemy Products API using Python Flask, SQL Alchemy and Marshmallow Quick Start Using Pipenv # Activate venv $ pipenv shell

amirwahla 1 Jan 01, 2022
A simple demo of using aiogram + async sqlalchemy 1.4+

aiogram-and-sqlalchemy-demo A simple demo of using aiogram + async sqlalchemy 1.4+ Used tech: aiogram SQLAlchemy 1.4+ PostgreSQL as database asyncpg a

Aleksandr 68 Dec 31, 2022
Formatting of dates and times in Flask templates using moment.js.

Flask-Moment This extension enhances Jinja2 templates with formatting of dates and times using moment.js. Quick Start Step 1: Initialize the extension

Miguel Grinberg 358 Nov 28, 2022
An easy way to build your flask skeleton.

Flider What is Flider Flider is a lightweight framework that saves you time by creating a MVC compliant file structure and includes basic commonly use

Trevor Engen 8 Nov 17, 2022
A nice anonymous messaging api (Uses Flask's restful api)

anonymous-message-api A nice anonymous message api (Uses Flask's restful api) How it works: 1. The user send a put request to your api server: Require

6 Nov 07, 2021
Glauth management ui created with python/flask

glauth-ui Glauth-UI is a small flask web app i created to manage the minimal glauth ldap server. I created this as i wanted to use glauth for authenti

Nils Thiele 67 Nov 29, 2022
A simple example using Flask inside a container

This is a simple example of how create a container for a Python Flask Web Application using Docker.

Fazt Web 8 Aug 30, 2022
This is a repository for a playlist of videos where I teach building RESTful API with Flask and Flask extensions.

Build And Deploy A REST API with Flask This is code for a series of videos in which we look at the various concepts involved when building a REST API

Ssali Jonathan 10 Nov 24, 2022
Force SSL on your Flask app.

Flask-SSLify This is a simple Flask extension that configures your Flask application to redirect all incoming requests to HTTPS. The extension is no l

Kenneth Reitz 26 Dec 07, 2022
Small flask based opds catalog designed to serve a directory via OPDS

teenyopds Small flask based opds catalog designed to serve a directory via OPDS, it has currently only been verified to work with KyBook 3 on iOS but

Adam Furbee 4 Jul 14, 2022
A YouTube webscraper made with flask.

YouTube Webscraper This website is for you to check all the stats on your favorite Youtube video! Technologies Python Flask HTML CSS Pafy Contributing

Proconsulates 3 Nov 25, 2021
Flask pre-setup architecture. This can be used in any flask project for a faster and better project code structure.

Flask pre-setup architecture. This can be used in any flask project for a faster and better project code structure. All the required libraries are already installed easily to use in any big project.

Ajay kumar sharma 5 Jun 14, 2022
Python Flask API service, backed by DynamoDB, running on AWS Lambda using the traditional Serverless Framework.

Serverless Framework Python Flask API service backed by DynamoDB on AWS Python Flask API service, backed by DynamoDB, running on AWS Lambda using the

Andreu Jové 0 Apr 17, 2022
flask extension for integration with the awesome pydantic package

Flask-Pydantic Flask extension for integration of the awesome pydantic package with Flask. Installation python3 -m pip install Flask-Pydantic Basics v

249 Jan 06, 2023