Django pyfilesystem integration
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for django_pyfs-2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0fc677459d74341fb94724d993bd1ec9251b3c3f9e83fc3b0e9c73fa44bd43c |
|
MD5 | 6c45a7ed5e47a95389882d187059a41f |
|
BLAKE2b-256 | b9c244483b54eb6dcc7776abd0221460bd4848ef9ae985755cca9e79fae7331d |
Hashes for django_pyfs-2.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c7280fc369220024f7056e082771d2d0be2f88707b1d4c2fd4e2cbe247f0f1e |
|
MD5 | 757066c82d915f1158fd21c2f28f8fb5 |
|
BLAKE2b-256 | a24c972d9fcfd14f03935fea1a86967f2652e0aad77ac240ad53b2ffa3cf51f7 |