I was curious to know if, how Spring boot has JPA repository to communicate with databases, Python also has anything similar?
If not, what would be a good way to structure my app such that a service layer would community with a dao layer? An example/demonstration would be great!
You can use python framework such as Django, Flask etc.
ORM provided by these frameworks are quite good and easier to write complex SQL queries.
For instance,
If I have to execute this SQL query to filter all users with name has "stack" keyword, then SQL query & django query will be like -
SELECT * from users where name LIKE '%stack%'; // SQL
Users.objects.filter(name__contains="stack") // Django
The best part about these ORMs is that they allow all of the functionality provided by SQL queries and JPA repository.
You can refer to Django/Flask docs to more info.
Related
We have inherited a DynamoDB database and have been told that a custom script is required if we want to edit/delete multiple items. ie you can't just run an easy mysql query to do this like in a relational database.
What is the most common way this is done? e.g. python script, lambda, etc.
thanks
You can connect to DynamoDB programmatically through a variety of SDKs (Javascript, .Net, Java, Go, C++, Ruby, Python, etc),in the AWS web UI console, and through the AWS command line interface (among others). I don't think it's terribly different than other databases in that regard.
If you are just getting started, I'd start by writing a script in your preferred programming languages with one of the many SDKs available. The NoSQL Workbench (an app available from Amazon directly) has a useful Operation Builder that will not only help with query syntax, but will even create a script to execute the operation in Java, Javascript and Python.
The DynamoDB API references the operations you can perform on DynamoDB (CRUD operations, transactions, etc). Each API method has a section at the bottom of the page with links to examples of that method being called in each of the supported SDKs. To mutate multiple items at once, you may want to check out the Batch operations (BatchWriteItem, BatchGetItem).
I'm not entirely sure I understand the advice you were given. DynamoDB is a noSQL database, so you cannot access it via SQL queries. NoSQL databases can come with a steep learning curve. I wouldn't say it's any harder than working with SQL databases, just different.
Familiarize yourself with DynamoDB data modeling, it is very different than data modeling in SQL databases. When learning DynamoDB, try hard to forget everything you know about working with SQL databases. Trying to find the SQL equivalent for something in DynamoDB consistently gives people a hard time.
I would highly recommend The Dynamo Guide to start the learning process. Again, it's not hard, just different than SQL databases. The AWS docs can be a bit terse, so I found resources like The DynamoDB Guide to be a lifesaver!
I am over accustomed to Django ORM and feel handicapped when trying to build a standalone python-twisted application which needs database integration.
SQLAlchemy looks promising - true. But I am trying to tinker with twisted as well and am unable to find anything on the lines of a good async python orm.
what I have found (https://stackoverflow.com/a/1705987/338691) would force me to write raw sql queries - doesn't feel quite right after my elongated stint with django.
So how does one play with database schema in a twisted application?
There is also http://findingscience.com/twistar/ which unfortunately follows the Active Record pattern and last time I checked, the author feels that migrations are out of scope of the project. So you would end up writing migrations manually anyway (maybe there could be some adapter for alembic for that, that would be cool).
Also I remember seeing github repo where the author tries to make twisted play nicely with sqlalchemy (without deferToThread) but I haven't followed to see if it was a success and can't find the URL. (also Twisted + SQLAlchemy and the best way to do it)
And lastly, recent versions of psycopg supports setting an async callback. Maybe that could be leveraged to something (integration with SQLAlchemy? or something).
UPDATE: also recently appeared this interesting project - alchimia
I have a regular desktop application which is written in Python/GTK and SQLObject as ORM. My goal is to create a webinterface where a user can login and sync/edit the database. My application is split up in different modules, so the database and gtk code are completly separate, so I would like to run the same database code on the webserver too.
So, I would like to know if there's a webframework which could handle these criteria:
User authentication
Use my own database code/SQLObject
Some widgets to build a basic ui
This would be my first webproject, so I'm a bit confused by all searchresults. CherryPy, Turbogears, web2py, Pyramid? I would be happy if someone could give me some pointers what would be a good framework in my situation.
Any of the options you name would work. Scan through their docs, and decide what looks like the nicest to you.
Flask is another lightweight option: http://flask.pocoo.org/
Django would work too (just ignore its ORM for your own work, and configure it to look at a different database within your database server, to keep it separated from your own ORM).
Try the pyramid, it does not impose anything you like as opposed to Django. And has a wealth of features for building Web applications at any level.
I'm trying to learn how to create a database for the school storage and a friend told me that it can be done with Python. Is that true ? If not, where can I learn about programming databases besides MySQL ?.
Also how can I create a friendly GUI to help the user with the database?
Your best bet is to find a Python driver/connector for the database of your choice.
A database (or more specifically Relational Database Management System, RDBMS) is a piece of software that is specially designed to handle data. Python, in and of itself, is not sufficient in this regard; you still need a database like MySql.
But you can connect to MySql from python using a connector or driver. The connectors that are available for MySQL are here: http://www.mysql.com/products/connector/
I have personnaly already use SQL database with python. I use sqlalchemy.
https://www.sqlalchemy.org
There is a really good official documentation
https://docs.sqlalchemy.org/en/13/orm/tutorial.html
I'd like to use the Python version of App Engine but rather than write my code specifically for the Google Data Store, I'd like to create my models with a generic Python ORM that could be attached to Big Table, or, if I prefer, a regular database at some later time. Is there any Python ORM such as SQLAlchemy that would allow this?
Technically this wouldn't be called an ORM (Object Relational Mapper) but a DAL (Database Abstraction Layer). The ORM part is not really interesting for AppEngine as the API already takes care of the object mapping and does some simple relational mapping (see RelationProperty).
Also realize that a DAL will never let you switch between AppEngine's datastore and a "normal" sql database like mysql because they work very differently. It might let you switch between different key value stores, like reddis, mongo or tokyo cabinet. But as they all have such very different characteristics I would really think twice before using one.
Lastly, the DAL traditionally sits on top of the DB interface, but with AppEngine's api you can implement your own "stubs" that basically let you use other storage backends on their api. The people at Mongo wrote one for MongoDB which is very nice. And the dev_appserver comes with a filesystem-based one.
And now to the answer: yes there is one! It's part of web.py. I haven't really tried if for the reasons above, so I can't really say if it's good.
PS. I know Ruby has a nice DAL project for keyvalue stores in the works too, but I can't find it now... Maybe nice to port to Python at some point.
Nowadays they do since Google has launched Cloud SQL