Package: cryptoassets.django
Cryptoassets library integration for DjangoThis package provides integration ofcryptoassets.coreBitcoin and  cryptoasset framework forDjango web framework.FeaturesUse Djangosettings.pyconfigure mechanism to set upcryptoassets.coreDjango management command mappings forcryptoassets helper serviceDjango native loggingDjango event dispatch integrationSetting up SQLAlchemy sessions and database conflict resolution inside DjangoUsageAddcryptoassets.djangoto your Django application list insettings.py:INSTALLED_APPS = (
    'cryptoassets.django',
)Addcryptoassets.core configurationas Python dictionary to your Djangosettings.pymodule underCRYPTOASSETSvariable.Example forsettings.py:# TESTNET settings
CRYPTOASSETS = {

    # 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:
    # http://cryptoassetscore.readthedocs.org/en/latest/config.html#database
    "database": {
        "url": "postgresql://localhost/cryptoassets",
        "echo": False,
    },

    # Configure block.io 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": "127.0.0.1",
        "port": 9001
    }
}NoteIf you copy-paste these settings please sign up at block.io for your own API key.Initializing databaseRun:python manage.py cryptoassets_initialize_databaseThis will build database tables for configured cryptocurrencies.This is Django management command warpper forcryptoassets-initialize-database.Starting cryptoassets helper serviceStart a helper service. This standalone process runs, connects to APIs and networks, listens to incoming transactions, broadcasts outgoing transaction.NoteCryptoassets helper service does not run within your web server process. It runs as a standalone process on your server.Run:python manage.py cryptoassets_helper_serviceFor more information seehelper service command.Handling incoming transactionsMake surewalletnotifyis configured inCRYPTOASSETSsetting as described above. It will translate incoming interprocess communication to Django events.Grab incoming transactions in your application code intxupdatesignal:from cryptoassets.django.signals import txupdate
from django.dispatch import receiver

@receiver(txupdate)
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
        return

    transaction_hash = data["txid"]
    value = data['amount']
    address = data['address']
    confirmations = int(data.get('confirmations', -1))

    logger.info("Transaction update received: %s BTC:%s address:%s confirmations:%d", transaction_hash, value, address, confirmations)The handler is executed insidecryptoassets helper serviceprocess.More information about cryptoassets.core events.Accessing cryptoassets dataAccessing database modelsTo get access to database models:from cryptoassets.django.app import get_cryptoassets

cryptoassets = get_cryptoassets()
BitcoinWallet = cryptoassets.coins.get("btc").coin_description.WalletMaking database queriesAll database access goes through a separate SQLAlcemy session which is wrapped withdatabase transaction conflict resolver.For convenience,cryptoassets.django.assetsdb.managed_transaction()decorator is provided:Example code:from cryptoassets.django.app 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):

    @assetdb.managed_transaction
    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)
        logging.info("Created receiving address %s", addr.address)
        address = addr.address
        return address

    return tx()The rest is bymodel APIandSQLAlchemy.OtherExample Django applicationSee Liberty Music Store(source code).cryptoassets.core tutorialSee getting started.Running helper service as system serviceTo have automatic start/stop and other functionality for cryptoassets helper service, use something akinsystemdorsupervisordto managepython manage.py cryptoassets_helper_service.AuthorMikko Ohtamaa (blog,Facebook,Twitter,Google+)