Skip to main content

Django pyfilesystem integration

Project description

django-pyfs

A Django module which extends pyfilesystem2 with several methods to make it convenient for web use. Specifically, it extends pyfilesystem2 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 for a while. 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 pyfilesystem2. 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)

State: This code is tested and has worked well in a range of settings, and is currently deployed on edx.org.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-pyfs-2.2.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

django_pyfs-2.2-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file django-pyfs-2.2.tar.gz.

File metadata

  • Download URL: django-pyfs-2.2.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.5.6

File hashes

Hashes for django-pyfs-2.2.tar.gz
Algorithm Hash digest
SHA256 ef2b8b53ccba59590df9934eed2ea97ce9c65088124644e59fc6774d54e3176f
MD5 619605ec8773bcc5de3845171337dcde
BLAKE2b-256 b75de430b72488488e4d3a2b94c5a4bcbc58093aa4dccf23a598c3e4601b59ca

See more details on using hashes here.

File details

Details for the file django_pyfs-2.2-py3-none-any.whl.

File metadata

  • Download URL: django_pyfs-2.2-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.5.6

File hashes

Hashes for django_pyfs-2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c3b9e78da216ed3310c13f40ffc281425b608ae4c1082eaa35c012c87dbfb004
MD5 8ad433160e91c09594ec41ad5a815cf6
BLAKE2b-256 c9ac4500490dbfc6b915ea7f74456069f3a7191977d4ffc277d338f21812216d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page