• Stars
    star
    203
  • Rank 192,890 (Top 4 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 11 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An ODBC-powered MS SQL Server DB backend for Django 1.4+

django-pyodbc

version

django-pyodbc is a Django SQL Server DB backend powered by the pyodbc library. pyodbc is a mature, viable way to access SQL Server from Python in multiple platforms and is actively maintained. It's also used by SQLAlchemy for SQL Server connections.

This is a fork of the original django-pyodbc, hosted on Google Code and last updated in 2011.

Features

  • [x] Alpha support for Django 2.0 via pip install django-pyodbc>=2.0.0a1
  • [x] Alpha support for Django 3.1 via pip install django-pyodbc>=2.0.0a2
  • [x] Support for Django 1.4-1.10.
  • [x] Support for SQL Server 2000, 2005, 2008, and 2012 (please let us know if you have success running this backend with another version of SQL Server)
  • [x] Support for Openedge 11.6
  • [x] Support for IBM's DB2
  • [x] Native Unicode support. Every string that goes in is stored as Unicode, and every string that goes out of the database is returned as Unicode. No conversion to/from intermediate encodings takes place, so things like max_length in CharField works just like expected.
  • [x] Both Windows Authentication (Integrated Security) and SQL Server Authentication.
  • [x] LIMIT+OFFSET and offset w/o LIMIT emulation under SQL Server 2005.
  • [x] LIMIT+OFFSET under SQL Server 2000.
  • [x] Django's TextField both under SQL Server 2000 and 2005.
  • [x] Passes most of the tests of the Django test suite.
  • [x] Compatible with SQL Server and SQL Server Native Client from Microsoft (Windows) and FreeTDS ODBC drivers (Linux).

TODO

  • [ ] Python 3 support. See #47 for details.

Installation

  1. Install django-pyodbc.

    pip install django-pyodbc
  2. Now you can now add a database to your settings using standard ODBC parameters.

    DATABASES = {
       'default': {
           'ENGINE': "django_pyodbc",
           'HOST': "127.0.0.1,1433",
           'USER': "mssql_user",
           'PASSWORD': "mssql_password",
           'NAME': "database_name",
           'OPTIONS': {
               'host_is_server': True
           },
       }
    }
  3. That's it! You're done.*

    * You may need to configure your machine and drivers to do an ODBC connection to your database server, if you haven't already. For Linux this involves installing and configuring Unix ODBC and FreeTDS . Iterate on the command line to test your pyodbc connection like:

    python -c 'import pyodbc; print(pyodbc.connect("DSN=foobar_mssql_data_source_name;UID=foo;PWD=bar").cursor().execute("select 1"))'

    extended instructions here

Configuration

The following settings control the behavior of the backend:

Standard Django settings

NAME String. Database name. Required.

HOST String. SQL Server instance in server\instance or ip,port format.

PORT String. SQL Server port.

USER String. Database user name. If not given then MS Integrated Security
will be used.

PASSWORD String. Database user password.

OPTIONS Dictionary. Current available keys:

  • driver

    String. ODBC Driver to use. Default is "SQL Server" on Windows and "FreeTDS" on other platforms.

  • dsn

    String. A named DSN can be used instead of HOST.

  • autocommit

    Boolean. Indicates if pyodbc should direct the the ODBC driver to activate the autocommit feature. Default value is False.

  • MARS_Connection

    Boolean. Only relevant when running on Windows and with SQL Server 2005 or later through MS SQL Server Native client driver (i.e. setting driver to "SQL Server Native Client 11.0"). See http://msdn.microsoft.com/en-us/library/ms131686.aspx. Default value is False.

  • host_is_server

    Boolean. Only relevant if using the FreeTDS ODBC driver under Unix/Linux.

    By default, when using the FreeTDS ODBC driver the value specified in the HOST setting is used in a SERVERNAME ODBC connection string component instead of being used in a SERVER component; this means that this value should be the name of a dataserver definition present in the freetds.conf FreeTDS configuration file instead of a hostname or an IP address.

    But if this option is present and it's value is True, this special behavior is turned off.

    See http://freetds.org/userguide/dsnless.htm for more information.

  • extra_params

    String. Additional parameters for the ODBC connection. The format is "param=value;param=value".

  • collation

    String. Name of the collation to use when performing text field lookups against the database. For Chinese language you can set it to "Chinese_PRC_CI_AS". The default collation for the database will be used if no value is specified.

  • encoding

    String. Encoding used to decode data from this database. Default is 'utf-8'.

  • driver_needs_utf8

    Boolean. Some drivers (FreeTDS, and other ODBC drivers?) don't support Unicode yet, so SQL clauses' encoding is forced to utf-8 for those cases.

    If this option is not present, the value is guessed according to the driver set.

  • limit_table_list

    Boolean. This will restrict the table list query to the dbo schema.

  • openedge

    Boolean. This will trigger support for Progress Openedge

  • left_sql_quote , right_sql_quote

    String. Specifies the string to be inserted for left and right quoting of SQL identifiers respectively. Only set these if django-pyodbc isn't guessing the correct quoting for your system.

OpenEdge Support

For OpenEdge support make sure you supply both the deiver and the openedge extra options, all other parameters should work the same

Tests

To run the test suite:

python tests/runtests.py --settings=test_django_pyodbc

License

This project originally started life as django-sql-server. This project was abandoned in 2011 and was brought back to life as django-pyodbc by our team in 2013. In the process, most of the project was refactored and brought up to speed with modern Django best practices. The work done prior to the 2013 rewrite is licensed under BSD (3-Clause). Improvements since then are licensed under Apache 2.0. See LICENSE for more details.

SemVer

This project implements Semantic Versioning .

Credits

From the original project README.

  • All the Django core developers, especially Malcolm Tredinnick. For being an example of technical excellence and for building such an impressive community.
  • The Oracle Django team (Matt Boersma, Ian Kelly) for some excellent ideas when it comes to implement a custom Django DB backend.

More Repositories

1

bottlenose

A Python wrapper for the Amazon Product Advertising API.
Python
578
star
2

pinboard.py

A full-featured Python wrapper (and command-line utility) for the Pinboard API. Built by the makers of Pushpin for Pinboard.
Python
342
star
3

openradar-mirror

A mirror of radars pulled from http://openradar.me/.
Python
246
star
4

git-bigstore

Bigstore is a Git extension that helps you track big files in your repositories.
Python
183
star
5

ConcentricProgressRingView

Fully customizable circular progress bar written in Swift.
Swift
143
star
6

LHSKeyboardAdjusting

An easy-to-use Objective-C protocol that automatically resizes / adjusts views when a keyboard appears on iOS.
Objective-C
100
star
7

ASPinboard

A modern, fast, and flexible Objective-C library for Pinboard.in.
Objective-C
83
star
8

TipJarViewController

Easy, drop-in tip jar for iOS apps.
Swift
78
star
9

requests-cloudkit

Apple CloudKit Python library.
Python
70
star
10

django-template

A battle-tested Django 2.1 project template with configurations for AWS, Heroku, App Engine, and Docker.
Python
64
star
11

in_app_purchase_receipt_verifier

A simple, one-click deploy web app to simplify the process of validating In-App Purchase receipts on the App Store.
Python
58
star
12

python-harvest

A Python wrapper for the Harvest time-tracking API.
Python
55
star
13

SuperLayout

SuperLayout is a Swift library that makes using Auto Layout a breeze.
Swift
52
star
14

django-on-appengine-archive

Jumpstart Django development on Google Appengine.
Python
49
star
15

pwnedpasswords

A Python Library and CLI for the Pwned Passwords v2 API
Python
47
star
16

KeyboardAdjuster

A Swift library that automatically resizes and adjusts views to scroll when a keyboard appears.
Swift
40
star
17

objectifier

Objectify your Python objects.
Python
37
star
18

TimeTracker-Linux

A Harvest client for Ubuntu Linux.
Python
21
star
19

Notchy

Notchy is an iOS app that makes pretty, shareable screenshots for the iPhone X and the iPhone XS.
Swift
20
star
20

LionheartExtensions

An invaluable collection of Swift extensions and utilities for iOS.
Swift
14
star
21

django-pwnedpasswords-validator

Django password validator that checks for passwords in known data breaches.
Python
13
star
22

python-onfleet

A full-featured Python wrapper for the Onfleet API.
Python
11
star
23

TableViewPopoverPresenting

Display popovers on taps over your table views cells. It was hard. Now it's easy.
Swift
9
star
24

QuickTableView

UITableView toolset for Swift.
Swift
9
star
25

python-leafly

Python
8
star
26

django-lionheart-helpers

A small collection of utilities for use with Django.
Python
8
star
27

django-statictastic

A Django app that makes it easy to sync static files to your storage backend of choice.
Python
8
star
28

python-restmapper

RestMapper takes the pain out of integrating with RESTful APIs.
Python
8
star
29

LionheartCurrencyTextField

A drop-in replacement for UITextField that displays currency values the way you’d expect it to.
Swift
8
star
30

LHSFontSelectionViewController

Objective-C
7
star
31

WelcomeViewController

A welcome view in the style of Apple's built-in apps.
Swift
7
star
32

LHSColorPickerView

Objective-C
4
star
33

fastlane-plugin-submit_to_beta_app_review

A simple plugin that submits an iTunes Connect build to Beta App Review.
Ruby
4
star
34

Health-XML-Splitter

A macOS utility that splits Health XML files into smaller chunks.
Swift
4
star
35

pushpin-localizations

Translations for Pushpin, a Pinboard client for iOS.
Shell
3
star
36

LHSDelicious

An easy-to-use Objective-C wrapper for the Delicious API.
Objective-C
3
star
37

Xcode-Templates

Makefile
3
star
38

LHSCategoryCollection

A collection of helpful categories for use in iOS projects.
Objective-C
3
star
39

style-guide

2
star
40

LHSCategoriesFlowView

Objective-C
2
star
41

iOSTipsTricks

Objective-C
2
star
42

IAPReceiptVerifier

Companion iOS library to https://github.com/lionheart/in_app_purchase_receipt_verifier
Swift
2
star
43

LHSKippt

not much to see here, move along
Objective-C
2
star
44

milestonemaker

Just a quick and dirty script that creates weekly milestones in GitHub issues.
Python
2
star
45

UncommonCrypto

Pure Swift wrapper for CommonCrypto.
HTML
2
star
46

LHSDiigo

Objective-C
2
star
47

LionheartOtherAppsViewController

A view controller that showcases all the apps you currently have on the App Store.
Swift
2
star
48

LHSTableViewCells

A Pod that allows you to make tableViewCells without subclassing them
Objective-C
1
star
49

LHSTwitterFollowUtility

A utility that allows your users to follow a specific twitter account.
Objective-C
1
star
50

mixpanel-people-delete

A one-click Heroku app that resets your Mixpanel People usage.
Python
1
star
51

github-issues-tools

Python
1
star
52

LHSCustomTransitionCollection

A collection of custom transitions for use in iOS 7+
Objective-C
1
star
53

releasemaker

Python
1
star
54

LionheartAlamofireClient

A simple class that helps manage interaction with remote APIs using Alamofire.
Swift
1
star
55

LHSOtherAppsViewController

A view controller to show your users the other apps that you have developed.
Objective-C
1
star
56

lionheart-tumblr-theme

The Lionheart Software Tumblr Blog Theme
CSS
1
star