This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Cryptoassets library integration for Django

This package provides integration of cryptoassets.core Bitcoin and cryptoasset framework for Django web framework.


  • Use Django configure mechanism to set up cryptoassets.core
  • Django management command mappings for cryptoassets helper service
  • Django native logging
  • Django event dispatch integration
  • Setting up SQLAlchemy sessions and database conflict resolution inside Django


Add cryptoassets.django to your Django application list in


Add cryptoassets.core configuration as Python dictionary to your Django module under CRYPTOASSETS variable.

Example for

# TESTNET settings

    # It is recommended to use separate database for cryptoassets,
    # but you can share the database with Django as well.
    # In any case, cryptoassets
    # will use a separate db connection.
    # cryptoassets.django does not read the existing DATABASES setting.
    # Configure the connection using SQLAlchemy syntax:
    "database": {
        "url": "postgresql://localhost/cryptoassets",
        "echo": False,

    # Configure API service with Bitcoin testnet
    # (let's not play around with real Bitcoins yet)
    "coins": {
        "btc": {
            "backend": {
                "class": "cryptoassets.core.backend.blockio.BlockIo",
                "api_key": "923f-xxxx-yyyy-zzzz",
                "network": "btctest",
                "pin": "foobar123",
                # Cryptoassets helper process will use this UNIX named pipe to communicate
                # with bitcoind
                "walletnotify": {
                    "class": "cryptoassets.core.backend.sochainwalletnotify.SochainWalletNotifyHandler",
                    "pusher_app_key": "e9f5cc20074501ca7395"

    # Bind cryptoassets.core event handler to Django dispacth wrapper
    "events": {
        "django": {
            "class": "cryptoassets.core.event.python.InProcessEventHandler",
            "callback": "cryptoassets.django.incoming.handle_tx_update"

    # Start simple status at port 9001 for diagnostics
    "status_server": {
        "ip": "",
        "port": 9001


If you copy-paste these settings please sign up at for your own API key.

Initializing database


python cryptoassets_initialize_database

This will build database tables for configured cryptocurrencies.

This is Django management command warpper for cryptoassets-initialize-database.

Starting cryptoassets helper service

Start a helper service. This standalone process runs, connects to APIs and networks, listens to incoming transactions, broadcasts outgoing transaction.


Cryptoassets helper service does not run within your web server process. It runs as a standalone process on your server.


python cryptoassets_helper_service

For more information see helper service command.

Handling incoming transactions

Make sure walletnotify is configured in CRYPTOASSETS setting as described above. It will translate incoming interprocess communication to Django events.

Grab incoming transactions in your application code in txupdate signal:

from cryptoassets.django.signals import txupdate
from django.dispatch import receiver

def txupdate_received(event_name, data, **kwargs):
    """ Received transaction update from cryptoassets.core.


    if data.get("transaction_type") != "deposit":
        # We are only interest updates on incoming transctions

    transaction_hash = data["txid"]
    value = data['amount']
    address = data['address']
    confirmations = int(data.get('confirmations', -1))"Transaction update received: %s BTC:%s address:%s confirmations:%d", transaction_hash, value, address, confirmations)

The handler is executed inside cryptoassets helper service process.

More information about cryptoassets.core events.

Accessing cryptoassets data

Accessing database models

To get access to database models:

from import get_cryptoassets

cryptoassets = get_cryptoassets()
BitcoinWallet = cryptoassets.coins.get("btc").coin_description.Wallet

Making database queries

All database access goes through a separate SQLAlcemy session which is wrapped with database transaction conflict resolver.

For convenience, cryptoassets.django.assetsdb.managed_transaction() decorator is provided:

Example code:

from import get_cryptoassets
from cryptoassets.django import assetdb

def get_wallet(session):
    """Return the master shared wallet used to receive payments. """
    cryptoassets = get_cryptoassets()
    BitcoinWallet = cryptoassets.coins.get("btc").coin_description.Wallet
    wallet = BitcoinWallet.get_or_create_by_name("default", session)
    return wallet

def create_new_receiving_address(label):

    def tx(session):

        wallet = get_wallet(session=session)

        account = wallet.get_or_create_account_by_name("my account")
        session.flush()  # account id gets written inside commit
        addr = wallet.create_receiving_address(account, label)"Created receiving address %s", addr.address)
        address = addr.address
        return address

    return tx()

The rest is by model API and SQLAlchemy.


Example Django application

See Liberty Music Store (source code).

cryptoassets.core tutorial

See getting started.

Running helper service as system service

To have automatic start/stop and other functionality for cryptoassets helper service, use something akin systemd or supervisord to manage python cryptoassets_helper_service.


Mikko Ohtamaa (blog, Facebook, Twitter, Google+)

Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date (15.9 kB) Copy SHA256 Checksum SHA256 Source Mar 9, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting