Python数据库WITHOUT使用Django(用于Heroku) [英] Python database WITHOUT using Django (for Heroku)

查看:179
本文介绍了Python数据库WITHOUT使用Django(用于Heroku)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对我来说,我还没有在别的地方找到这个问题。短版本,我正在写一个应用程序,我计划部署到云(可能使用Heroku),这将进行各种网络抓取和数据收集。它将在云中的原因是,我可以将其设置为自己每天运行,并将数据拉到其数据库,而不是我的计算机,以及所以团队的其余人可以访问数据。



我曾经使用过AWS的SimpleDB和DynamoDB,但是我发现SDB的存储限制是小的,DDB的查询能力很差是一个问题,所以我寻找可以存储任意长度值(以及理想的任意数据结构)并且可以在任何字段上查询的数据库系统(SQL或NoSQL)。



为Heroku找到了许多数据库解决方案,如ClearDB,但我所看到的所有信息都展示了如何设置Django来访问数据库。因为这是为了脚本,而不是一个网站,我真的不喜欢去潜水Django,如果我不必。



有任何种类的

解决方案

我会使用MongoDB的数据库,我可以用Python连接到Heroku。 Heroku已经支持它了,所以我认为它很容易启动和扩展: https://addons.heroku .com / mongohq



关于Python:MongoDB是一个非常简单的数据库。该模式是灵活的,非常适合Python字典。这是非常好的。



您可以使用 PyMongo

 来自pymongo import Connection 
connection = Connection()

#获取您的DB
db = connection.my_database

#获取您的集合
cars = db.cars

#创建一些对象
import datetime
car = {brand:Ford,
model:Mustang,
date:datetime.datetime.utcnow()}

#插入它
cars.insert(car)

很简单, / p>

希望它有帮助。



EDIT:

正如Endophage所提到的,与Mongo连接的另一个好的选择是 mongoengine 。如果你有大量的数据要存储,你应该看看那。


To my surprise, I haven't found this question asked elsewhere. Short version, I'm writing an app that I plan to deploy to the cloud (probably using Heroku), which will do various web scraping and data collection. The reason it'll be in the cloud is so that I can have it be set to run on its own every day and pull the data to its database without my computer being on, as well as so the rest of the team can access the data.

I used to use AWS's SimpleDB and DynamoDB, but I found SDB's storage limitations to be to small and DDB's poor querying ability to be a problem, so I'm looking for a database system (SQL or NoSQL) that can store arbitrary-length values (and ideally arbitrary data structures) and that can be queried on any field.

I've found many database solutions for Heroku, such as ClearDB, but all of the information I've seen has shown how to set up Django to access the database. Since this is intended to be script and not a site, I'd really prefer not to dive into Django if I don't have to.

Is there any kind of database that I can hook up to in Heroku with Python without using Django?

解决方案

I'd use MongoDB. Heroku has support for it, so I think it will be really easy to start and scale out: https://addons.heroku.com/mongohq

About Python: MongoDB is a really easy database. The schema is flexible and fits really well with Python dictionaries. That's something really good.

You can use PyMongo

from pymongo import Connection
connection = Connection()

# Get your DB
db = connection.my_database

# Get your collection
cars = db.cars

# Create some objects
import datetime
car = {"brand": "Ford",
       "model": "Mustang",
       "date": datetime.datetime.utcnow()}

# Insert it
cars.insert(car)

Pretty simple, uh?

Hope it helps.

EDIT:

As Endophage mentioned, another good option for interfacing with Mongo is mongoengine. If you have lots of data to store, you should take a look at that.

这篇关于Python数据库WITHOUT使用Django(用于Heroku)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆