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

Related tags

Flask flask-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
Serve angular production application from python flask backend. Quick and Easy

Serve angular production application from python flask backend. Quick and Easy

mark 1 Dec 1, 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
flask-apispec MIT flask-apispec (🥉24 · ⭐ 520) - Build and document REST APIs with Flask and apispec. MIT

flask-apispec flask-apispec is a lightweight tool for building REST APIs in Flask. flask-apispec uses webargs for request parsing, marshmallow for res

Joshua Carp 617 Dec 30, 2022
Brandnew-flask is a CLI tool used to generate a powerful and mordern flask-app that supports the production environment.

Brandnew-flask is still in the initial stage and needs to be updated and improved continuously. Everyone is welcome to maintain and improve this CLI.

brandonye 4 Jul 17, 2022
Flask-app scaffold, generate flask restful backend

Flask-app scaffold, generate flask restful backend

jacksmile 1 Nov 24, 2021
Freezes a Flask application into a set of static files.

Frozen-Flask Freezes a Flask application into a set of static files. The result can be hosted without any server-side software other than a traditiona

Frozen Flask 737 Dec 19, 2022
Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for your application.

Flask-Bcrypt Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for your application. Due to the recent increased prevelance of

Max Countryman 310 Dec 14, 2022
Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for your application.

Flask-Bcrypt Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for your application. Due to the recent increased prevelance of

Max Countryman 282 Feb 11, 2021
Flask-Starter is a boilerplate starter template designed to help you quickstart your Flask web application development.

Flask-Starter Flask-Starter is a boilerplate starter template designed to help you quickstart your Flask web application development. It has all the r

Kundan Singh 259 Dec 26, 2022
Flask-Rebar combines flask, marshmallow, and swagger for robust REST services.

Flask-Rebar Flask-Rebar combines flask, marshmallow, and swagger for robust REST services. Features Request and Response Validation - Flask-Rebar reli

PlanGrid 223 Dec 19, 2022
Flask Project Template A full feature Flask project template.

Flask Project Template A full feature Flask project template. See also Python-Project-Template for a lean, low dependency Python app. HOW TO USE THIS

Bruno Rocha 96 Dec 23, 2022
A Fast API style support for Flask. Gives you MyPy types with the flexibility of flask

Flask-Fastx Flask-Fastx is a Fast API style support for Flask. It Gives you MyPy types with the flexibility of flask. Compatibility Flask-Fastx requir

Tactful.ai 18 Nov 26, 2022
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
Pf-flask-rest-com - Flask REST API Common Implementation by Problem Fighter Library

In the name of God, the Most Gracious, the Most Merciful. PF-Flask-Rest-Com Docu

Problem Fighter 3 Jan 15, 2022
Flask-Discord-Bot-Dashboard - A simple discord Bot dashboard created in Flask Python

Flask-Discord-Bot-Dashboard A simple discord Bot dashboard created in Flask Pyth

Ethan 8 Dec 22, 2022
Open-source Flask Sample built on top of flask-dance library

Open-source Flask Sample built on top of flask-dance library. The project implements the social login for Github and Twitter - Originally coded by TestDriven.IO.

App Generator 4 Jul 26, 2022
Flask-redmail - Email sending for Flask

Flask Red Mail: Email Sending for Flask Flask extension for Red Mail What is it?

Mikael Koli 11 Sep 23, 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

null 6 Jan 6, 2023