|  | DB access without object-relation mapping? |  | |
| | | kj |  |
| Posted: Tue Jul 29, 2008 3:20 pm Post subject: DB access without object-relation mapping? |  |
Python noob here.
I want to write a script that creates and populates a simple Postgres database.
The word on the street is to use something like SQLAlchemy for database access in Python, but my experience in the past with packages that perform automated SQL generation has been awful, so I always return to lighter-weight solutions that allow me to write my own SQL. (E.g. when coding in Perl I've used Perl's DBI package and drivers, rather than the likes of Class::DBI.) So what's the standard Python way to send SQL directly to a Postgres database and get back results?
TIA!
kynn
-- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded. |
| |
| | | Tim Henderson |  |
| Posted: Tue Jul 29, 2008 3:25 pm Post subject: Re: DB access without object-relation mapping? |  |
On Jul 29, 11:20 am, kj <so...@987jk.com.invalid> wrote:
| Quote: | Python noob here.
I want to write a script that creates and populates a simple Postgres database.
The word on the street is to use something like SQLAlchemy for database access in Python, but my experience in the past with packages that perform automated SQL generation has been awful, so I always return to lighter-weight solutions that allow me to write my own SQL. (E.g. when coding in Perl I've used Perl's DBI package and drivers, rather than the likes of Class::DBI.) So what's the standard Python way to send SQL directly to a Postgres database and get back results?
TIA!
kynn
-- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded.
|
Hi,
I believe there are a couple of options but pyscopg, and PyGreSQL seem to be popular.
Tim |
| |
| | | Paul Boddie |  |
| Posted: Tue Jul 29, 2008 3:58 pm Post subject: Re: DB access without object-relation mapping? |  |
On 29 Jul, 17:20, kj <so...@987jk.com.invalid> wrote:
| Quote: | So what's the standard Python way to send SQL directly to a Postgres database and get back results?
|
Take a look at this page:
LINK
I've used psycopg2 and pyPgSQL successfully, although pg_proboscis looks very interesting, too.
Paul |
| |
| | | kj |  |
| Posted: Tue Jul 29, 2008 5:24 pm Post subject: Re: DB access without object-relation mapping? |  |
In <cbe3cdad-c437-46a9-98df-2eb5b2cef3ce@56g2000hsm.googlegroups.com> Tim Henderson <tim.tadh@gmail.com> writes:
| Quote: | I believe there are a couple of options but pyscopg, and PyGreSQL seem to be popular.
|
Great. Thanks!
kynn -- NOTE: In my address everything before the first period is backwards; and the last period, and everything after it, should be discarded. |
| |
| | | Ben Finney |  |
| Posted: Tue Jul 29, 2008 9:14 pm Post subject: Re: DB access without object-relation mapping? |  |
| |  | |
kj <socyl@987jk.com.invalid> writes:
| Quote: | The word on the street is to use something like SQLAlchemy for database access in Python, but my experience in the past with packages that perform automated SQL generation has been awful, so I always return to lighter-weight solutions that allow me to write my own SQL.
|
Using SQLAlchemy, you *can* write your own SQL (with its 'text' query type to feed explicit SQL text on the connection); you just don't *need* to for the majority of simple and not-so-simple cases.
I've been using SQLAlchemy for some time and have found its combination of "make the simple cases simple" and "allow full control when needed" to be close to ideal. I can use exactly the same interface to leverage the SQL generation for mundane tasks and to craft custom weird SQL that I need.
Combine that with active, level-headed maintenance, and comprehensive documentation, and I don't even need to consider using the ORM layer :-)
-- \ “Know what I hate most? Rhetorical questions.†—Henry N. Camp | `\ | _o__) | Ben Finney |
| |
|
|