Code Monkey home page Code Monkey logo

django-pyfs's Introduction

django-pyfs

A Django module which extends pyfilesystem with several methods to make it convenient for web use. Specifically, it extends pyfilesystem with two methods:

fs.get_url(filename, timeout=0)

This will return a externally-usable URL to the resource. If timeout>0, the URL may stop working after that period (in seconds). Details are implementation-dependent. On Amazon S3, this is a secure URL, which is only available for that period. For a static filesystem, the URLs are unsecure and permanent.

fs.expire(filename, seconds, days, expires=True)

This allows us to create temporary objects. Our use-case was that we wanted to generate visualizations to users which were .png images. The lifetime of those images was a single web request, so we set them to expire after a few minutes. Another use case was memoization.

Note that expired files are not automatically removed. To remove them, call expire_objects(). In our system, we had a cron job do this. Celery, manual removals, etc. are all options.

To configure a django-pyfs to use static files, set a parameter in Django settings:

DJFS = {'type' : 'osfs',
                 'directory_root' : 'djpyfs/static/djpyfs', 
                 'url_root' : '/static/djpyfs'}

Here, directory_root is where the files go. url_root is the URL base of where your web server is configured to serve them from.

To use files on S3, you need boto installed. Then,

DJFS = {'type' : 's3fs',
        'bucket' : 'my-bucket', 
        'prefix' : '/pyfs/' } 

bucket is your S3 bucket. prefix is optional, and gives a base within that bucket.

To get your filesystem, call:

def get_filesystem(namespace)

Each module should pass a unique namespace. These will typically correspond to subdirectories within the filesystem.

The django-pyfs interface is designed as a generic (non-Django specific) extension to pyfilesystem. However, the specific implementation is very Django-specific.

Good next steps would be to:

  • Allow Django storages to act as a back-end for pyfilesystem
  • Allow django-pyfs to act as a back-end for Django storages
  • Support more types of pyfilesystems (esp. in-memory would be nice)
  • General code cleanup, documentation, test cases, etc.
  • Add better test support. Django does nice things with resetting DBs to a know state for testing. It'd be nice to do the same here.

State: This code is tested and has worked well in a range of settings. I did just tease it out of a couple of projects which were using it, so there may be issues associated with this, but it does appear to work. Much of the codebase could use a cleanup -- it's not pretty. I also cannot commit to long-term interface stability (but older versions ought to continue to work). .

django-pyfs's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.