Skip to content

Commit 6184a43

Browse files
committed
updating ORMs page
1 parent 30a37e4 commit 6184a43

File tree

8 files changed

+368
-58
lines changed

8 files changed

+368
-58
lines changed

all.html

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,21 +3283,43 @@ <h2>Why are ORMs useful?</h2>
32833283
<a href="/databases.html">relational database</a> that allows a developer to write
32843284
Python code instead of SQL to create, read, update and delete data in
32853285
their database. Developers can use the programming language they are
3286-
comfortable with, in our case Python, to work with data and not have to
3287-
write SQL statements or stored procedures.</p>
3288-
<p>However, Python ORM libraries are not required for accessing relational
3289-
databases. In fact, the low-level access is typically provided by another
3290-
library, such as <a href="http://initd.org/psycopg/">psycopg</a> (for PostgreSQL)
3291-
or <a href="https://pypi.python.org/pypi/MySQL-python/1.2.5">MySQL-python</a> (for
3292-
MySQL).</p>
3293-
<p>Developers can also use ORMs without a web framework, such as when
3294-
creating a data analysis tool or a batch script without a user interface. </p>
3286+
comfortable with to work with a database instead of writing SQL statements or
3287+
stored procedures.</p>
3288+
<p>The ability to write Python code instead of SQL can speed up web application
3289+
development, especially at the beginning of a project. The potential
3290+
development speed boost comes from not having to switch from Python code
3291+
into writing declarative paradigm SQL statements. While some software
3292+
developers may not mind switching back and forth between languages, it's
3293+
typically easier to knock out a prototype or start a web application using
3294+
a single programming language.</p>
3295+
<p>ORMs also make it theoretically possible to switch an application between
3296+
various relational databases. For example, a developer could use SQLite for
3297+
local development and MySQL in production. A production application could
3298+
be switched from MySQL to PostgreSQL with minimal code modifications. </p>
3299+
<p>In reality however, it's best to use the same database for local development
3300+
as is used in production. Otherwise unexpected errors could hit in production
3301+
that were not seen in a local development environment. Also, it's rare that
3302+
a project would switch from one database in production to another one unless
3303+
there was a pressing reason.</p>
32953304
<div class="well see-also">
32963305
While you're learning about ORMs you should also read up on
32973306
<a href="/deployment.html">deployment</a> and check out the
32983307
<a href="/application-dependencies.html">application dependencies</a> page.
32993308
</div>
33003309

3310+
<h2>Do I have to use an ORM for my web application?</h2>
3311+
<p>Python ORM libraries are not required for accessing relational
3312+
databases. In fact, the low-level access is typically provided by another
3313+
library called a <em>database connector</em>, such as
3314+
<a href="http://initd.org/psycopg/">psycopg</a> (for PostgreSQL)
3315+
or <a href="https://pypi.python.org/pypi/MySQL-python/1.2.5">MySQL-python</a> (for
3316+
MySQL). Take a look at the table below which shows that ORMs can work with
3317+
different web frameworks and database connectors.</p>
3318+
<p><img src="theme/img/orm-examples.png" width="100%" alt="Examples of how varying Python ORMs can work with different connectors and backends." class="technical-diagram" /></p>
3319+
<p>For example, in the above table SQLAlchemy can work with or without an
3320+
accompanying web framework as well as different database connectors.
3321+
Developers can also use ORMs without a web framework, such as when creating
3322+
a data analysis tool or a batch script without a user interface. </p>
33013323
<h2>What are the downsides of using an ORM?</h2>
33023324
<p>There are numerous downsides of ORMs, including</p>
33033325
<ol>
@@ -3307,8 +3329,9 @@ <h2>What are the downsides of using an ORM?</h2>
33073329
<li>shifting complexity into the application from the database layer</li>
33083330
</ol>
33093331
<h2>Django's ORM</h2>
3310-
<p>The <a href="/django.html">Django</a> web framework comes with its own built-in
3311-
object-relational mapping module, generally referred to as "the Django ORM".</p>
3332+
<p>The <a href="/django.html">Django</a> web framework comes with
3333+
its own built-in object-relational mapping module, generally referred to
3334+
as "the Django ORM" or "Django's ORM".</p>
33123335
<p><a href="https://docs.djangoproject.com/en/dev/topics/db/">Django's ORM</a> works well
33133336
for simple and medium-complexity database operations. However, there are often
33143337
complaints that the ORM makes complex queries much more complicated than
@@ -3324,19 +3347,27 @@ <h2>Django's ORM</h2>
33243347
read up on advanced use cases and tools for doing your best work within the
33253348
existing framework.</p>
33263349
<h2>SQLAlchemy</h2>
3327-
<p><a href="http://www.sqlalchemy.org/">SQLAlchemy</a> is currently the most respected
3328-
Python ORM because it typically get the abstraction level "just right" and
3329-
seems to make complex database queries easier to write than the Django ORM
3330-
in most cases. SQLAlchemy is typically used with Flask as the database ORM
3331-
via the <a href="https://pythonhosted.org/Flask-SQLAlchemy/">Flask-SQLAlchemy</a>
3350+
<p><a href="http://www.sqlalchemy.org/">SQLAlchemy</a> is
3351+
currently the most respected Python ORM because it typically get the
3352+
abstraction level "just right" and seems to make complex database queries
3353+
easier to write than the Django ORM in most cases. SQLAlchemy is typically
3354+
used with Flask as the database ORM via the
3355+
<a href="https://pythonhosted.org/Flask-SQLAlchemy/">Flask-SQLAlchemy</a>
33323356
extension.</p>
33333357
<h2>Peewee</h2>
3334-
<p><a href="https://peewee.readthedocs.org/en/latest/">Peewee</a> is another Python ORM
3358+
<p><a href="https://peewee.readthedocs.org/en/latest/">Peewee</a> is a Python ORM
33353359
written to be
3336-
<a href="http://charlesleifer.com/blog/the-case-for-peewee-small-hackable-and-fun/">simpler, smaller and more hackable</a>
3360+
"<a href="http://charlesleifer.com/blog/the-case-for-peewee-small-hackable-and-fun/">simpler, smaller and more hackable</a>"
33373361
than SQLAlchemy. The analogy used by the core Peewee author is that Peewee
33383362
is to SQLAlchemy as SQLite is to PostgreSQL. An ORM does not have to work
33393363
for every exhaustive use case in order to be useful.</p>
3364+
<h2>Pony</h2>
3365+
<p><a href="http://ponyorm.com/">Pony ORM</a> is another Python ORM with a slight twist in
3366+
its licensing model. The project is multi-licensed. Pony is free for use
3367+
on open source projects but has a
3368+
<a href="http://ponyorm.com/license-and-pricing.html">commercial license</a> that
3369+
is required for commercial projects. The license is a one-time payment
3370+
and does not necessitate a recurring fee.</p>
33403371
<h2>Schema migrations</h2>
33413372
<p>Schema migrations, for example when you need to add a new column to an
33423373
existing table in your database, are not technically part of ORMs. However,
@@ -3478,6 +3509,19 @@ <h3>Peewee resources</h3>
34783509
<a href="https://peewee.readthedocs.org/en/latest/">Peewee ORM</a> instead of
34793510
SQLAlchemy for the blog back end.</p>
34803511
</li>
3512+
</ul>
3513+
<h2>Pony ORM resources</h2>
3514+
<ul>
3515+
<li>
3516+
<p><a href="http://jakeaustwick.me/why-you-should-give-ponyorm-a-chance/">Why you should give Pony ORM a chance</a>
3517+
explains some of the benefits of Pony ORM that make it worth trying out.</p>
3518+
</li>
3519+
<li>
3520+
<p>The Pony ORM author explains on a Stack Overflow answer
3521+
<a href="http://stackoverflow.com/questions/16115713/how-pony-orm-does-its-tricks">how Pony ORM works behind the scenes</a>.
3522+
Worth a read whether or not you're using the ORM just to find out how
3523+
some of the magic coding works.</p>
3524+
</li>
34813525
</ul>
34823526
<h1>Application Programming Interfaces</h1>
34833527
<p>Application programming interfaces (APIs) provide machine-readable

feeds/all.atom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<feed xmlns="http://www.w3.org/2005/Atom"><title>Matt Makai</title><link href="http://www.fullstackpython.com/" rel="alternate"></link><link href="http://www.fullstackpython.com/feeds/all.atom.xml" rel="self"></link><id>http://www.fullstackpython.com/</id><updated>2015-06-14T12:57:51Z</updated></feed>
2+
<feed xmlns="http://www.w3.org/2005/Atom"><title>Matt Makai</title><link href="http://www.fullstackpython.com/" rel="alternate"></link><link href="http://www.fullstackpython.com/feeds/all.atom.xml" rel="self"></link><id>http://www.fullstackpython.com/</id><updated>2015-06-14T17:14:32Z</updated></feed>

object-relational-mappers-orms.html

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,43 @@ <h2>Why are ORMs useful?</h2>
4343
<a href="/databases.html">relational database</a> that allows a developer to write
4444
Python code instead of SQL to create, read, update and delete data in
4545
their database. Developers can use the programming language they are
46-
comfortable with, in our case Python, to work with data and not have to
47-
write SQL statements or stored procedures.</p>
48-
<p>However, Python ORM libraries are not required for accessing relational
49-
databases. In fact, the low-level access is typically provided by another
50-
library, such as <a href="http://initd.org/psycopg/">psycopg</a> (for PostgreSQL)
51-
or <a href="https://pypi.python.org/pypi/MySQL-python/1.2.5">MySQL-python</a> (for
52-
MySQL).</p>
53-
<p>Developers can also use ORMs without a web framework, such as when
54-
creating a data analysis tool or a batch script without a user interface. </p>
46+
comfortable with to work with a database instead of writing SQL statements or
47+
stored procedures.</p>
48+
<p>The ability to write Python code instead of SQL can speed up web application
49+
development, especially at the beginning of a project. The potential
50+
development speed boost comes from not having to switch from Python code
51+
into writing declarative paradigm SQL statements. While some software
52+
developers may not mind switching back and forth between languages, it's
53+
typically easier to knock out a prototype or start a web application using
54+
a single programming language.</p>
55+
<p>ORMs also make it theoretically possible to switch an application between
56+
various relational databases. For example, a developer could use SQLite for
57+
local development and MySQL in production. A production application could
58+
be switched from MySQL to PostgreSQL with minimal code modifications. </p>
59+
<p>In reality however, it's best to use the same database for local development
60+
as is used in production. Otherwise unexpected errors could hit in production
61+
that were not seen in a local development environment. Also, it's rare that
62+
a project would switch from one database in production to another one unless
63+
there was a pressing reason.</p>
5564
<div class="well see-also">
5665
While you're learning about ORMs you should also read up on
5766
<a href="/deployment.html">deployment</a> and check out the
5867
<a href="/application-dependencies.html">application dependencies</a> page.
5968
</div>
6069

70+
<h2>Do I have to use an ORM for my web application?</h2>
71+
<p>Python ORM libraries are not required for accessing relational
72+
databases. In fact, the low-level access is typically provided by another
73+
library called a <em>database connector</em>, such as
74+
<a href="http://initd.org/psycopg/">psycopg</a> (for PostgreSQL)
75+
or <a href="https://pypi.python.org/pypi/MySQL-python/1.2.5">MySQL-python</a> (for
76+
MySQL). Take a look at the table below which shows that ORMs can work with
77+
different web frameworks and database connectors.</p>
78+
<p><img src="theme/img/orm-examples.png" width="100%" alt="Examples of how varying Python ORMs can work with different connectors and backends." class="technical-diagram" /></p>
79+
<p>For example, in the above table SQLAlchemy can work with or without an
80+
accompanying web framework as well as different database connectors.
81+
Developers can also use ORMs without a web framework, such as when creating
82+
a data analysis tool or a batch script without a user interface. </p>
6183
<h2>What are the downsides of using an ORM?</h2>
6284
<p>There are numerous downsides of ORMs, including</p>
6385
<ol>
@@ -67,8 +89,9 @@ <h2>What are the downsides of using an ORM?</h2>
6789
<li>shifting complexity into the application from the database layer</li>
6890
</ol>
6991
<h2>Django's ORM</h2>
70-
<p>The <a href="/django.html">Django</a> web framework comes with its own built-in
71-
object-relational mapping module, generally referred to as "the Django ORM".</p>
92+
<p>The <a href="/django.html">Django</a> web framework comes with
93+
its own built-in object-relational mapping module, generally referred to
94+
as "the Django ORM" or "Django's ORM".</p>
7295
<p><a href="https://docs.djangoproject.com/en/dev/topics/db/">Django's ORM</a> works well
7396
for simple and medium-complexity database operations. However, there are often
7497
complaints that the ORM makes complex queries much more complicated than
@@ -84,19 +107,27 @@ <h2>Django's ORM</h2>
84107
read up on advanced use cases and tools for doing your best work within the
85108
existing framework.</p>
86109
<h2>SQLAlchemy</h2>
87-
<p><a href="http://www.sqlalchemy.org/">SQLAlchemy</a> is currently the most respected
88-
Python ORM because it typically get the abstraction level "just right" and
89-
seems to make complex database queries easier to write than the Django ORM
90-
in most cases. SQLAlchemy is typically used with Flask as the database ORM
91-
via the <a href="https://pythonhosted.org/Flask-SQLAlchemy/">Flask-SQLAlchemy</a>
110+
<p><a href="http://www.sqlalchemy.org/">SQLAlchemy</a> is
111+
currently the most respected Python ORM because it typically get the
112+
abstraction level "just right" and seems to make complex database queries
113+
easier to write than the Django ORM in most cases. SQLAlchemy is typically
114+
used with Flask as the database ORM via the
115+
<a href="https://pythonhosted.org/Flask-SQLAlchemy/">Flask-SQLAlchemy</a>
92116
extension.</p>
93117
<h2>Peewee</h2>
94-
<p><a href="https://peewee.readthedocs.org/en/latest/">Peewee</a> is another Python ORM
118+
<p><a href="https://peewee.readthedocs.org/en/latest/">Peewee</a> is a Python ORM
95119
written to be
96-
<a href="http://charlesleifer.com/blog/the-case-for-peewee-small-hackable-and-fun/">simpler, smaller and more hackable</a>
120+
"<a href="http://charlesleifer.com/blog/the-case-for-peewee-small-hackable-and-fun/">simpler, smaller and more hackable</a>"
97121
than SQLAlchemy. The analogy used by the core Peewee author is that Peewee
98122
is to SQLAlchemy as SQLite is to PostgreSQL. An ORM does not have to work
99123
for every exhaustive use case in order to be useful.</p>
124+
<h2>Pony</h2>
125+
<p><a href="http://ponyorm.com/">Pony ORM</a> is another Python ORM with a slight twist in
126+
its licensing model. The project is multi-licensed. Pony is free for use
127+
on open source projects but has a
128+
<a href="http://ponyorm.com/license-and-pricing.html">commercial license</a> that
129+
is required for commercial projects. The license is a one-time payment
130+
and does not necessitate a recurring fee.</p>
100131
<h2>Schema migrations</h2>
101132
<p>Schema migrations, for example when you need to add a new column to an
102133
existing table in your database, are not technically part of ORMs. However,
@@ -239,6 +270,19 @@ <h3>Peewee resources</h3>
239270
SQLAlchemy for the blog back end.</p>
240271
</li>
241272
</ul>
273+
<h2>Pony ORM resources</h2>
274+
<ul>
275+
<li>
276+
<p><a href="http://jakeaustwick.me/why-you-should-give-ponyorm-a-chance/">Why you should give Pony ORM a chance</a>
277+
explains some of the benefits of Pony ORM that make it worth trying out.</p>
278+
</li>
279+
<li>
280+
<p>The Pony ORM author explains on a Stack Overflow answer
281+
<a href="http://stackoverflow.com/questions/16115713/how-pony-orm-does-its-tricks">how Pony ORM works behind the scenes</a>.
282+
Worth a read whether or not you're using the ORM just to find out how
283+
some of the magic coding works.</p>
284+
</li>
285+
</ul>
242286
<h3>What would you like to learn about building Python web apps?</h3>
243287
<div class="row">
244288
<div class="col-md-4">

0 commit comments

Comments
 (0)