Skip to main content

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

Metadata

Release files for django-pyfs 3.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-pyfs 3.2.0
File Size Uploaded
django-pyfs-3.2.0.tar.gz 18.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-pyfs 3.2.0
File Interpreter ABI Platform
django_pyfs-3.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 31.3 kB

Release files / django-pyfs-3.2.0.tar.gz

Download URL django-pyfs-3.2.0.tar.gz
Size 18.0 kB
Tags Source
SHA-256 checksum
How to use checksums
190f550f56c34ca561bff690aeeb3a7de92acb0bbf78a10d49c7c4d4dda32424
BLAKE2b-256 checksum
How to use checksums
9c60b5bbda5c0fd56040c444dc8212e7c155c838f9930c6ed756763223ea647a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

Release files / django_pyfs-3.2.0-py3-none-any.whl

Download URL django_pyfs-3.2.0-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8495013cb6f291812df9241debc14937531da7ed2f3bf6519cf0a5fe109b77cf
BLAKE2b-256 checksum
How to use checksums
9a98f4ddc31133e1c14fccb81f7f19b10d6555d3750f737a8a390a5526d13f1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

Release history Release notifications | RSS feed

This release

3.2.0 This release

2 release files

3.1.0

2 release files

3.0

2 release files

2.2

2 release files

2.1

2 release files

2.0

3 release files

1.0.7

3 release files

1.0.6

3 release files

1.0.5

3 release files

1.0.4

1 release file

1.0.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page