pylons
Should I use Pylons or Pyramid?
Pylons isn’t being “cancelled”, and it will continue to receive updates. That said, the “future” per se is in Pyramid. On the mailing list is has been referred to as Pylons 2.0. It is fully tested and better documented than Pylons 1.0, so you might as well jump aboard if you’re fresh. Pyramid is essentially … Read more
get path of python binary that’s executing the script [duplicate]
The path is available in sys.executable.
sqlalchemy existing database query
You seem to have an impression that SQLAlchemy can only work with a database structure created by SQLAlchemy (probably using MetaData.create_all()) – this is not correct. SQLAlchemy can work perfectly with a pre-existing database, you just need to define your models to match database tables. One way to do that is to use reflection, as … Read more
How to efficiently manage frequent schema changes using sqlalchemy?
Alembic is a new database migrations tool, written by the author of SQLAlchemy. I’ve found it much easier to use than sqlalchemy-migrate. It also works seamlessly with Flask-SQLAlchemy. Auto generate the schema migration script from your SQLAlchemy models: alembic revision –autogenerate -m “description of changes” Then apply the new schema changes to your database: alembic … Read more
SQLAlchemy printing raw SQL from create()
from sqlalchemy.schema import CreateTable print(CreateTable(table)) If you are using declarative syntax: print(CreateTable(Model.__table__)) Update: Since I have the accepted answer and there is important information in klenwell answer, I’ll also add it here. You can get the SQL for your specific database (MySQL, Postgresql, etc.) by compiling with your engine. print(CreateTable(Model.__table__).compile(engine)) Update 2: @jackotonye Added in … Read more
SQLAlchemy, clear database content but don’t drop the schema
I asked about the same thing on the SQLAlchemy Google group, and I got a recipe that appears to work well (all my tables are emptied). See the thread for reference. My code (excerpt) looks like this: import contextlib from sqlalchemy import MetaData meta = MetaData() with contextlib.closing(engine.connect()) as con: trans = con.begin() for table … Read more
How can I select all rows with sqlalchemy?
You can easily import your model and run this: from models import User # User is the name of table that has a column name users = User.query.all() for user in users: print user.name
How to get column names from SQLAlchemy result (declarative syntax)
You can do something similar to Foo Stack’s answer without resorting to private fields by doing: conn.execute(query).keys()
UnicodeEncodeError: ‘latin-1’ codec can’t encode character
I ran into this same issue when using the Python MySQLdb module. Since MySQL will let you store just about any binary data you want in a text field regardless of character set, I found my solution here: Using UTF8 with Python MySQLdb Edit: Quote from the above URL to satisfy the request in the … Read more