Skip to main content

Django pyfilesystem integration

Project description

PyPI Github CI Codecov Supported Python versions License

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 openedx-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 openedx-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 openedx-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

openedx_django_pyfs-4.0.0.tar.gz (19.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openedx_django_pyfs-4.0.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file openedx_django_pyfs-4.0.0.tar.gz.

File metadata

  • Download URL: openedx_django_pyfs-4.0.0.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for openedx_django_pyfs-4.0.0.tar.gz
Algorithm Hash digest
SHA256 b8699ef19cb51ba7b1e091fef2447a024dce7eeff55d2faa456cf71599ee200e
MD5 6e14f8a05f01142bdf339f53aa39589f
BLAKE2b-256 a6851d5417d6c5723b1e01a77a9ee2d90a8aebac1156666396c2c25d5a2a59cc

See more details on using hashes here.

File details

Details for the file openedx_django_pyfs-4.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openedx_django_pyfs-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b4f16ba2f90546bbec9dbc947b157a2a81b8e344a9d2e0560a733c125f1e9ba3
MD5 a53b870808ab7c312fa0821543b06312
BLAKE2b-256 4ff21d044c4518d4861d6676c1303ff76321dff2724a44240088a17ff9bc2b71

See more details on using hashes here.

Supported by

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