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
É uma API feita em Python e Flask que pesquisa informações em uma tabela .xlsx e retorna o resultado.

API de rastreamento de pacotes É uma API feita em Python e Flask que pesquisa informações de rastreamento de pacotes em uma tabela .xlsx e retorna o r

Marcos Beraldo Barros 4 Jun 27, 2021
docker-compose uWSGI nginx flask

docker-compose uWSGI nginx flask Note that this was tested on CentOS 7 Usage sudo yum install docker

Abdolkarim Saeedi 3 Sep 11, 2022
Beautiful Interactive tables in your Flask templates.

flask-tables Beautiful interactive tables in your Flask templates Resources Video demonstration: Go to YouTube video. Learn how to use this code: Go t

Miguel Grinberg 209 Jan 05, 2023
A clean and simple blog system based on Flask and MongoDB

CleanBlog A clean and simple blog system based on Flask and MongoDB You can access CleanBlog This is the source code of Flask Tutorial Pro,you can buy

shin 107 Oct 06, 2022
A Flask extension that enables or disables features based on configuration.

Flask FeatureFlags This is a Flask extension that adds feature flagging to your applications. This lets you turn parts of your site on or off based on

Rachel Greenfield 131 Sep 26, 2022
A swagger 2.0 spec extractor for flask

flask-swagger A Swagger 2.0 spec extractor for Flask You can now specify base path for yml files: app = Flask(__name__) @app.route("/spec") def spec(

Sling 457 Dec 02, 2022
Flask Sitemapper is a small Python 3 package that generates XML sitemaps for Flask applications.

Flask Sitemapper Flask Sitemapper is a small Python 3 package that generates XML sitemaps for Flask applications. This allows you to create a nice and

6 Jan 06, 2023
Sample Dockerized flask app deployed on Kubernetes on Azure using AKS

Sample Dockerized flask app deployed on Kubernetes on Azure using AKS

Ahmed khémiri 22 Sep 08, 2021
PatientDB is a flask app to store patient information.

PatientDB PatientDB on Heroku "PatientDB is a simple web app that stores patient information, able to edit the information, and able to query the data

rbb 2 Jan 31, 2022
YAML-formatted plain-text file based models for Flask backed by Flask-SQLAlchemy

Flask-FileAlchemy Flask-FileAlchemy is a Flask extension that lets you use Markdown or YAML formatted plain-text files as the main data store for your

Siddhant Goel 20 Dec 14, 2022
Full-Stack application that visualizes amusement park safety.

Amusement Park Ride Safety Analysis Project Proposal We have chosen to look into amusement park data to explore ride safety relationships visually, in

Michael Absher 0 Jul 11, 2021
Example Flask application illustrating some of my common practices

Overholt Overholt is an example Flask application illustrating some of my common practices Development Environment At the bare minimum you'll need the

Matt Wright 1.6k Dec 15, 2022
API to get the details of the characters in the Money heist TV show.

Project Heist Description: Project Heist is a RESTful API made using Python and Flask. This API is inspired by the popular Spanish TV show Money Heist

Rahul V 5 Dec 19, 2022
This repo contains the Flask API to expose model and get predictions.

Tea Leaf Quality Srilanka Chapter This repo contains the Flask API to expose model and get predictions. Expose Model As An API Model Trainig will happ

DuKe786 2 Nov 12, 2021
:rocket: Generate a Postman collection from your Flask application

flask2postman A tool that creates a Postman collection from a Flask application. Install $ pip install flask2postman Example Let's say that you have a

Numberly 137 Nov 08, 2022
Geometry Dash Song Bypass with Python Flask Server

Geometry Dash Song Bypass with Python Flask Server

pixelsuft‮ 1 Nov 16, 2021
A simple barcode and QR code generator built in Python with Flask.

✨ Komi - Barcode & QR Generator ✨ A simple barcode and QR code generator built in Python with Flask. 📑 Table of Contents Usage Installation Contribut

Bonnie Fave 2 Nov 04, 2021
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
A gRpc server like Flask (像Flask一样的gRpc服务)

Mask A gRpc server just like Flask. Install Mask support pypi packages, you can simply install by: pip install mask Document Mask manual could be fou

吴东 16 Jun 14, 2022
Are-You-OK is a Flask-based, responsive Web App to monitor whether the Internet Service you care about is still working.

Are-You-OK Are-You-OK is a Flask-based, responsive Web App to monitor whether the Internet Service you care about is still working. Demo-Preview Get S

Tim Qiu 1 Oct 28, 2021