Skip to main content

IPFS storage backend for Django.

Project description

Store Django file-uploads on the Interplanetary File System.

Uploads are added and pinned to the configured IPFS node, which returns the IPFS Content ID (a hash of the contents). This hash is the name that is saved to your database. Duplicate content will also have the same address, saving disk space.

Because of this only file creation and reading is supported.

Other IPFS users access and reseed a piece of content through its unique content ID. Differently-distributed (i.e. normal HTTP) users can access the uploads through an HTTP→IPFS gateway.

Installation

pip install django-ipfs-storage

Configuration

By default ipfs_storage adds and pins content to an IPFS daemon running on localhost and returns URLs pointing to the public https://ipfs.io/ipfs/ HTTP Gateway

To customise this, set the following variables in your settings.py:

  • IPFS_STORAGE_API_URL: defaults to 'http://localhost:5001/api/v0/'.

  • IPFS_GATEWAY_API_URL: defaults to 'https://ipfs.io/ipfs/'.

Set IPFS_GATEWAY_API_URL to 'http://localhost:8080/ipfs/' to serve content through your local daemon’s HTTP gateway.

Usage

There are two ways to use a Django storage backend.

As default backend

Use IPFS as Django’s default file storage backend:

# settings.py

DEFAULT_FILE_STORAGE = 'ipfs_storage.InterPlanetaryFileSystemStorage'

IPFS_STORAGE_API_URL = 'http://localhost:5001/api/v0/'
IPFS_STORAGE_GATEWAY_URL = 'http://localhost:8080/ipfs/'

For a specific FileField

Alternatively, you may only want to use the IPFS storage backend for a single field:

from django.db import models

from ipfs_storage import InterPlanetaryFileSystemStorage


class MyModel(models.Model):
    # …
    file_stored_on_ipfs = models.FileField(storage=InterPlanetaryFileSystemStorage())
    other_file = models.FileField()  # will still use DEFAULT_FILE_STORAGE

Don’t forget the brackets to instantiate InterPlanetaryFileSystemStorage() with the default arguments!

FAQ

Why IPFS?

Not my department. See https://ipfs.io/#why.

How do I ensure my uploads are always available?

I don’t know. Maybe look into using ipfs-cluster to spread it across a few nodes? Or perhaps you could integrate Eternum’s hosted pinning service.

How do I backup my uploads?

See above.

How do I delete an upload?

Because of the distributed nature of IPFS, anyone who accesses a piece of content keeps a copy, and reseeds it for you automatically until it’s evicted from their node’s local cache. Yay bandwidth costs! Boo censorship!

Unfortunately, if you’re trying to censor yourself (often quite necessary), this means the best we can do is unpin the piece of content from your own IPFS node(s) and hope nobody else has pinned it.

How do I securely expose my IPFS daemon’s API to connect remotely?

Someone please tell me.

How do I securely expose my own IPFS←HTTP Gateway?

Again, see above.

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-ipfs-storage-0.0.4.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

django_ipfs_storage-0.0.4-py2.py3-none-any.whl (6.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-ipfs-storage-0.0.4.tar.gz.

File metadata

File hashes

Hashes for django-ipfs-storage-0.0.4.tar.gz
Algorithm Hash digest
SHA256 dc978f0416cb7a9fb18d09021d2064bac1e418da55db5285733931a1bce75bfa
MD5 79e3250cf14724e81fcc0cec602ab24b
BLAKE2b-256 347ab69d57d382ae31c438b16a65a6e448305372446a4cb025ef565ca4ec1339

See more details on using hashes here.

File details

Details for the file django_ipfs_storage-0.0.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_ipfs_storage-0.0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 20783f09ccde8f7c944a3e5bab39ad19397fb6fda59c9095d2c7d4635336675f
MD5 213ecfd7d656c7d7c3ae992f82150827
BLAKE2b-256 12ec0cb14649bf8f196bbd2299d2076a051fe09cb73704f9e15f356d31f4c884

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