|
74 | 74 | </div> |
75 | 75 | <div class="row"> |
76 | 76 | <div class="col-md-8"> |
77 | | - <div class="section" id="id1"> |
78 | | -<h2>Databases</h2> |
79 | | -<p>A database is an abstraction on top of an operating system's file system to |
80 | | -ease creating, reading, updating, and deleting persistent data. The |
| 77 | + <h1>Databases</h1> |
| 78 | +<p>A database is an abstraction on top of an operating system's file system to |
| 79 | +ease creating, reading, updating, and deleting persistent data. The |
81 | 80 | database storage abstraction most commonly used in Python web development is |
82 | 81 | sets of relational tables. Alternative storage abstractions are explained in |
83 | | -the <a class="reference external" href="../no-sql-datastore.html">NoSQL</a> section of this guide.</p> |
| 82 | +the <a href="../no-sql-datastore.html">NoSQL</a> section of this guide.</p> |
84 | 83 | <p>Relational databases store all data in a series of tables. Interconnections |
85 | 84 | between the tables are specified as <em>foreign keys</em>.</p> |
86 | | -<p>Databases storage implementations vary in complexity. SQLite, a database |
87 | | -included with Python, creates a single file for all data per database. |
| 85 | +<p>Databases storage implementations vary in complexity. SQLite, a database |
| 86 | +included with Python, creates a single file for all data per database. |
88 | 87 | Other databases such as Oracle, PostgreSQL, and MySQL have more complicated |
89 | | -persistence schemes while offering additional advanced features that are |
| 88 | +persistence schemes while offering additional advanced features that are |
90 | 89 | useful for web application data storage.</p> |
91 | | -<p><a class="reference external" href="http://www.postgresql.org/">PostgreSQL</a> and |
92 | | -<a class="reference external" href="http://www.mysql.com/">MySQL</a> are two of the most common open source |
| 90 | +<p><a href="http://www.postgresql.org/">PostgreSQL</a> and |
| 91 | +<a href="http://www.mysql.com/">MySQL</a> are two of the most common open source |
93 | 92 | databases for storing Python web application data.</p> |
94 | | -<p><a class="reference external" href="http://www.sqlite.org/">SQLite</a> is a database that is stored in a single |
| 93 | +<p><a href="http://www.sqlite.org/">SQLite</a> is a database that is stored in a single |
95 | 94 | file on disk. SQLite is built into Python but is only built for access |
96 | 95 | by a single connection at a time. Therefore is highly recommended to not |
97 | | -<a class="reference external" href="https://docs.djangoproject.com/en/dev/ref/databases/#database-is-locked-errors">run a production web application with SQLite</a>.</p> |
98 | | -</div> |
99 | | -<div class="section" id="id2"> |
| 96 | +<a href="https://docs.djangoproject.com/en/dev/ref/databases/#database-is-locked-errors">run a production web application with SQLite</a>.</p> |
100 | 97 | <h2>PostgreSQL</h2> |
101 | 98 | <p>PostgreSQL is the recommended relational database for working with Python |
102 | 99 | web applications. PostgreSQL's feature set, active development and stability |
103 | 100 | contribute to its usage as the backend for millions of applications live |
104 | 101 | on the Web today.</p> |
105 | | -<div class="section" id="postgresql-resources"> |
106 | 102 | <h3>PostgreSQL resources</h3> |
107 | | -<p>This post on "<a class="reference external" href="http://killtheyak.com/use-postgresql-with-django-flask/">Use PostgreSQL with Django or Flask</a>" |
| 103 | +<p>This post on |
| 104 | +<a href="http://killtheyak.com/use-postgresql-with-django-flask/">using PostgreSQL with Django or Flask</a> |
108 | 105 | is a great quickstart guide for either framework.</p> |
109 | | -<p><a class="reference external" href="http://postgresweekly.com/">PostgreSQL Weekly</a> is a weekly newsletter of |
| 106 | +<p><a href="http://postgresweekly.com/">PostgreSQL Weekly</a> is a weekly newsletter of |
110 | 107 | PostgreSQL content from around the web.</p> |
111 | | -<p><a class="reference external" href="https://www.braintreepayments.com/braintrust/scaling-postgresql-at-braintree-four-years-of-evolution">Scaling PostgreSQL at Braintree</a>. Fascinating |
112 | | -inside look at the evolution of the database's usage at Braintree.</p> |
113 | | -<p><a class="reference external" href="http://www.ibm.com/developerworks/library/os-postgresecurity/">Total security in a PostgreSQL database</a>. |
| 108 | +<p>Braintree wrote about their experiences <a href="https://www.braintreepayments.com/braintrust/scaling-postgresql-at-braintree-four-years-of-evolution">scaling PostgreSQL</a>. |
| 109 | +The post is an inside look at the evolution of Braintree's usage of the database.</p> |
| 110 | +<p>There's no such thing as total security but this IBM article covers |
| 111 | +<a href="http://www.ibm.com/developerworks/library/os-postgresecurity/">hardening a PostgreSQL database</a>. |
114 | 112 | There is no such thing as total security but this is a good article anyway.</p> |
115 | | -<p><a class="reference external" href="http://www.craigkerstiens.com/2012/10/01/understanding-postgres-performance/">Understanding PostgreSQL performance</a></p> |
116 | | -<p><a class="reference external" href="http://instagram-engineering.tumblr.com/post/40781627982/handling-growth-with-postgres-5-tips-from-instagram">Handling growth with Postgres</a> |
| 113 | +<p>Craig Kerstien's wrote a detailed post about <a href="http://www.craigkerstiens.com/2012/10/01/understanding-postgres-performance/">understanding PostgreSQL performance</a>.</p> |
| 114 | +<p><a href="http://instagram-engineering.tumblr.com/post/40781627982/handling-growth-with-postgres-5-tips-from-instagram">Handling growth with Postgres</a> |
117 | 115 | provides 5 specific tips from Instagram's engineering team on how to scale |
118 | 116 | the design of your PostgreSQL database.</p> |
119 | | -</div> |
120 | | -</div> |
121 | | -<div class="section" id="id3"> |
122 | 117 | <h2>MySQL</h2> |
123 | | -<p>MySQL is another viable open source database backend option for Python web |
124 | | -applications. MySQL has a slightly easier initial learning curve than |
125 | | -PostgreSQL. The database is deployed in production at some of the highest |
126 | | -trafficked sites such as |
127 | | -<a class="reference external" href="https://blog.twitter.com/2012/mysql-twitter">Twitter</a>, |
128 | | -<a class="reference external" href="https://www.facebook.com/notes/facebook-engineering/mysql-and-database-engineering-mark-callaghan/10150599729938920">Facebook</a> |
129 | | -and <a class="reference external" href="http://www.mysql.com/customers/">many others major organizations</a>. |
130 | | -However, since the company focused on MySQL development, |
131 | | -<a class="reference external" href="http://en.wikipedia.org/wiki/MySQL_AB">MySQL AB</a>, was |
| 118 | +<p>MySQL is another viable open source database backend option for Python web |
| 119 | +applications. MySQL has a slightly easier initial learning curve than |
| 120 | +PostgreSQL. The database is deployed in production at some of the highest |
| 121 | +trafficked sites such as |
| 122 | +<a href="https://blog.twitter.com/2012/mysql-twitter">Twitter</a>, |
| 123 | +<a href="https://www.facebook.com/notes/facebook-engineering/mysql-and-database-engineering-mark-callaghan/10150599729938920">Facebook</a> |
| 124 | +and <a href="http://www.mysql.com/customers/">many others major organizations</a>. |
| 125 | +However, since the company focused on MySQL development, |
| 126 | +<a href="http://en.wikipedia.org/wiki/MySQL_AB">MySQL AB</a>, was |
132 | 127 | purchased by Sun Microsystems (which was in turn purchased by Oracle), there |
133 | 128 | have been major defections away from the database by |
134 | | -<a class="reference external" href="http://www.zdnet.com/wikipedia-moving-from-mysql-to-mariadb-7000008912/">Wikipedia</a> |
135 | | -and <a class="reference external" href="http://readwrite.com/2013/09/14/google-waves-goodbye-to-mysql-in-favor-of-mariadb">Google</a>. |
136 | | -MySQL remains a viable database option but I always recommend new Python |
| 129 | +<a href="http://www.zdnet.com/wikipedia-moving-from-mysql-to-mariadb-7000008912/">Wikipedia</a> |
| 130 | +and <a href="http://readwrite.com/2013/09/14/google-waves-goodbye-to-mysql-in-favor-of-mariadb">Google</a>. |
| 131 | +MySQL remains a viable database option but I always recommend new Python |
137 | 132 | developers learn PostgreSQL if they do not already know MySQL.</p> |
138 | | -<div class="section" id="mysql-resources"> |
139 | 133 | <h3>MySQL resources</h3> |
140 | | -<p><a class="reference external" href="http://designm.ag/tutorials/28-beginners-tutorials-for-learning-about-mysql-databases/">28 Beginner's Tutorials for Learning about MySQL Databases</a> |
| 134 | +<p><a href="http://designm.ag/tutorials/28-beginners-tutorials-for-learning-about-mysql-databases/">28 Beginner's Tutorials for Learning about MySQL Databases</a> |
141 | 135 | is a curated collection on various introductory MySQL topics.</p> |
142 | | -<p>This tutorial shows how to install <a class="reference external" href="http://www.cs.wcupa.edu/rkline/index/mysql-lin.html">MySQL on Ubuntu</a>.</p> |
143 | | -</div> |
144 | | -</div> |
145 | | -<div class="section" id="connecting-to-a-database-with-python"> |
| 136 | +<p>This tutorial shows how to install <a href="http://www.cs.wcupa.edu/rkline/index/mysql-lin.html">MySQL on Ubuntu</a>.</p> |
146 | 137 | <h2>Connecting to a database with Python</h2> |
147 | | -<p>To work with a relational database using Python, you need to use a code |
| 138 | +<p>To work with a relational database using Python, you need to use a code |
148 | 139 | library. The most common libraries for relational databases are:</p> |
149 | | -<p><a class="reference external" href="http://initd.org/psycopg/">psycopg2</a> for PostgreSQL</p> |
150 | | -<p><a class="reference external" href="https://pypi.python.org/pypi/MySQL-python/1.2.4">MySQLdb</a> for MySQL</p> |
151 | | -<p><a class="reference external" href="http://cx-oracle.sourceforge.net/">cx_Oracle</a> for Oracle</p> |
| 140 | +<ul> |
| 141 | +<li> |
| 142 | +<p><a href="http://initd.org/psycopg/">psycopg2</a> for PostgreSQL</p> |
| 143 | +</li> |
| 144 | +<li> |
| 145 | +<p><a href="https://pypi.python.org/pypi/MySQL-python/1.2.4">MySQLdb</a> for MySQL</p> |
| 146 | +</li> |
| 147 | +<li> |
| 148 | +<p><a href="http://cx-oracle.sourceforge.net/">cx_Oracle</a> for Oracle</p> |
| 149 | +</li> |
| 150 | +</ul> |
152 | 151 | <p>SQLite support is built into Python 2.7+ and therefore a separate library |
153 | | -is not necessary. Simply "import sqlite3" to begin interfacing with the |
| 152 | +is not necessary. Simply "import sqlite3" to begin interfacing with the |
154 | 153 | single file-based database.</p> |
155 | | -</div> |
156 | | -<div class="section" id="object-relational-mapping"> |
157 | 154 | <h2>Object-Relational Mapping</h2> |
158 | | -<p>Object-relational mappers (ORMs) allow developers to access data from a |
159 | | -backend by writing Python code instead of SQL queries. Each web |
160 | | -application framework handles integrating ORMs differently.</p> |
161 | | -<p>Django provides an ORM with its core functionality. Flask leaves using an |
162 | | -ORM up to an extension, such as |
163 | | -<a class="reference external" href="http://pythonhosted.org/Flask-SQLAlchemy/">Flask-SQLALchemy</a>.</p> |
| 155 | +<p>Object-relational mappers (ORMs) allow developers to access data from a |
| 156 | +backend by writing Python code instead of SQL queries. Each web |
| 157 | +application framework handles integrating ORMs differently. </p> |
| 158 | +<p>Django provides an ORM with its core functionality. Flask leaves using an |
| 159 | +ORM up to an extension, such as |
| 160 | +<a href="http://pythonhosted.org/Flask-SQLAlchemy/">Flask-SQLALchemy</a>. </p> |
164 | 161 | <p>Developers can also use ORMs without a web framework, such as when |
165 | | -creating a data analysis tool or a batch script without a user interface. |
| 162 | +creating a data analysis tool or a batch script without a user interface. |
166 | 163 | Currently, the most widely used stand-alone ORM written for Python is |
167 | | -<a class="reference external" href="http://www.sqlalchemy.org/">SQLAlchemy</a>.</p> |
168 | | -</div> |
169 | | -<div class="section" id="database-third-party-services"> |
| 164 | +<a href="http://www.sqlalchemy.org/">SQLAlchemy</a>.</p> |
170 | 165 | <h2>Database third-party services</h2> |
171 | | -<p>Numerous companies run scalable database servers as a hosted service. |
172 | | -Depending on the provider, there can be several advantages to using a |
| 166 | +<p>Numerous companies run scalable database servers as a hosted service. |
| 167 | +Depending on the provider, there can be several advantages to using a |
173 | 168 | hosted database third-party service:</p> |
174 | | -<ol class="arabic simple"> |
| 169 | +<ol> |
175 | 170 | <li>automated backups and recovery</li> |
176 | 171 | <li>tightened security configurations</li> |
177 | 172 | <li>easy vertical scaling</li> |
178 | 173 | </ol> |
179 | | -<p><a class="reference external" href="http://aws.amazon.com/rds/">Amazon Relational Database Service (RDS)</a> |
| 174 | +<p><a href="http://aws.amazon.com/rds/">Amazon Relational Database Service (RDS)</a> |
180 | 175 | provides pre-configured MySQL and PostgreSQL instances. The instances can |
181 | 176 | be scaled to larger or smaller configurations based on storage and performance |
182 | 177 | needs.</p> |
183 | | -<p><a class="reference external" href="https://developers.google.com/cloud-sql/">Google Cloud SQL</a> is a service |
| 178 | +<p><a href="https://developers.google.com/cloud-sql/">Google Cloud SQL</a> is a service |
184 | 179 | with managed, backed up, replicated, and auto-patched MySQL instances. Cloud |
185 | 180 | SQL integrates with Google App Engine but can be used independently as well.</p> |
186 | | -<div class="section" id="database-resources"> |
187 | | -<h3>Database resources</h3> |
188 | | -<p><a class="reference external" href="http://db-engines.com/en/ranking">DB-Engines</a> ranks the most popular |
| 181 | +<h2>Database resources</h2> |
| 182 | +<p><a href="http://db-engines.com/en/ranking">DB-Engines</a> ranks the most popular |
189 | 183 | database management systems.</p> |
190 | | -<p><a class="reference external" href="http://dbweekly.com/">DB Weekly</a> is a new (as of Feb 2014) weekly roundup |
191 | | -of general database articles and resources.</p> |
192 | | -</div> |
193 | | -</div> |
194 | | - |
| 184 | +<p><a href="http://dbweekly.com/">DB Weekly</a> is a weekly roundup of general database |
| 185 | +articles and resources.</p> |
195 | 186 | <br/> |
196 | 187 | Next read the |
197 | 188 | <a href="/wsgi-servers.html">wsgi servers</a> section. |
|
0 commit comments