This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

A Django module for execute custom sql query in a .sql file

Project Description
# django-query-execfile
**Django module for execute sql query in a file**

Full documentation for the project is available at []




# Overview

django-query-execfile is a simple library for execute .sql query file.

# Requirements

* Python (2.7.x )
* Django (1.5+ )

# Installation

Install using `pip`...

pip install django-query-execfile

# Usage & Example

This is content of a .sql file

DATE(customerPayment.created) AS created,
SUM(transaction.amount * transaction.exchange_rate) AS amount_exchanged
FROM shop_module_customerpayment customerPayment
LEFT JOIN shop_module_transaction transaction ON = customerPayment.transaction_id
WHERE (customerPayment.created BETWEEN %(from_date)s AND %(to_date)s)
GROUP BY DATE(customerPayment.created);

Usage example

from models import Order
from query_execfile import sql_execfile, raw_queryfile

result = sql_execfile('../datagrip/payment_transaction_stats.sql'),
params={'from_date': .., 'to_date': ..},
print result

rawQuerySet = raw_queryfile(Order, '../datagrip/order_rawquery.sql')
for order in rawQuerySet:

**mapResultToDict=True** will map results to a dict with key = first comment above the query.
So you can write multiple query in a single file and execute these query at once.

**includeDescription=True** will add a extra row at first as column header using description from the query.
In this case is _AS created_ and _AS amount_exchanged_

**Result return of that example:**

{"sum_customerPayment_amount_rate_exchanged_group_by_day": [

# Documentation & Support
Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-query-execfile-0.6.tar.gz (4.5 kB) Copy SHA256 Checksum SHA256 Source May 20, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS 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