我需要一个简单的python“数据库”,它可以在有多个用户的apache下工作

时间:2022-07-21 11:16:56

I've got a simple web app, written in Perl/CGI under apache, and it handles thousands of files/directories. It's sort of a web front end to a large set of similar data. The data is very simple - maybe 10 fields per record, and only one-two types of records. I'm learning python and I'm planning to move some of my Perl code to python, and this seems like a good first step.

我有一个简单的web应用程序,在apache下用Perl/CGI编写,它可以处理数千个文件/目录。它就像是一组类似数据的网络前端。数据非常简单——每个记录可能有10个字段,只有一到两种类型的记录。我正在学习python,并计划将一些Perl代码转移到python中,这似乎是很好的第一步。

I'm not ready to jump to Django yet, I don't think. So what I'm considering is straight-up python scripts that I can invoke from my Perl code to do basic CRUD operations on this metadata. The trick (I think) is that it needs to be safe for multiple users. This is, after all, a web server and multiple people can access this at the same time. The actual likelihood of this is small - it's an internal tool for my group without a lot of traffic - but I want to be safe, anyway.

我还没准备好去Django,我不认为。因此,我考虑的是直接的python脚本,我可以从Perl代码中调用这些脚本,对这些元数据执行基本的CRUD操作。诀窍(我认为)是它需要对多个用户是安全的。毕竟,web服务器和多人可以同时访问它。实际发生这种情况的可能性很小——对于我的团队来说,这是一个内部工具,没有太多的流量——但无论如何,我想要安全。

So, first... is there a simple database module/API that would act like a dict in python (just to make it simple)? I've read about Pickle, for example. I'd truly like to avoid anything with an SQL-like interface. Ideally, I really just want a python dictionary that's backed by a DB that manages concurrent access in an apache/Perl environment. This will probably be running on a Mac server (Mavericks).

所以,首先……是否有一个简单的数据库模块/API可以像python中的命令一样(只是为了简单)?例如,我读过关于泡菜的文章。我真的希望避免使用类似sql的接口。理想情况下,我只想要一个python字典,它由一个DB支持,该DB管理apache/Perl环境中的并发访问。这可能会在Mac服务器(Mavericks)上运行。

Eventually, I want to try some Django, so if I just need to bite the bullet and do that now, I might be talked into it. But I have no real experience with modern web UI's, so I was hoping to save that for later.

最后,我想尝试一下《被解救的姜戈》,所以如果我现在就需要咬紧牙关,我可能会被说服。但是我对现代web UI并没有真正的经验,所以我希望把它留到以后再说。

3 个解决方案

#1


1  

Plus to pickle you can try shelve:

另外,你也可以尝试腌制:

A “shelf” is a persistent, dictionary-like object. The difference with “dbm” databases is that the values (not the keys!) in a shelf can be essentially arbitrary Python objects — anything that the pickle module can handle. This includes most class instances, recursive data types, and objects containing lots of shared sub-objects. The keys are ordinary strings.

“shelf”是一种持久的、类似于字典的对象。与“dbm”数据库的不同之处在于,架子上的值(不是键!)本质上可以是任意的Python对象——pickle模块可以处理的任何东西。这包括大多数类实例、递归数据类型和包含大量共享子对象的对象。键是普通的弦。

or just json and text files.

或者只是json和文本文件。

#2


1  

Since you're already using Perl, consider using DBM::Deep.

由于您已经在使用Perl,请考虑使用DBM::Deep。

#3


0  

You could try Zodb

你可以试试Zodb

https://en.wikipedia.org/wiki/Zope_Object_Database

https://en.wikipedia.org/wiki/Zope_Object_Database

which seems to do something like what you are talking about.

就像你说的那样。

If you do try the framework / sql route, Web2py is quite easy to get started with eg. http://www.youtube.com/watch?v=dHu8O1gZOl0 shows how to make a multi user blog with db.

如果您确实尝试了框架/ sql路由,Web2py很容易从eg开始。http://www.youtube.com/watch?v=dHu8O1gZOl0展示了如何用db创建一个多用户博客。

#1


1  

Plus to pickle you can try shelve:

另外,你也可以尝试腌制:

A “shelf” is a persistent, dictionary-like object. The difference with “dbm” databases is that the values (not the keys!) in a shelf can be essentially arbitrary Python objects — anything that the pickle module can handle. This includes most class instances, recursive data types, and objects containing lots of shared sub-objects. The keys are ordinary strings.

“shelf”是一种持久的、类似于字典的对象。与“dbm”数据库的不同之处在于,架子上的值(不是键!)本质上可以是任意的Python对象——pickle模块可以处理的任何东西。这包括大多数类实例、递归数据类型和包含大量共享子对象的对象。键是普通的弦。

or just json and text files.

或者只是json和文本文件。

#2


1  

Since you're already using Perl, consider using DBM::Deep.

由于您已经在使用Perl,请考虑使用DBM::Deep。

#3


0  

You could try Zodb

你可以试试Zodb

https://en.wikipedia.org/wiki/Zope_Object_Database

https://en.wikipedia.org/wiki/Zope_Object_Database

which seems to do something like what you are talking about.

就像你说的那样。

If you do try the framework / sql route, Web2py is quite easy to get started with eg. http://www.youtube.com/watch?v=dHu8O1gZOl0 shows how to make a multi user blog with db.

如果您确实尝试了框架/ sql路由,Web2py很容易从eg开始。http://www.youtube.com/watch?v=dHu8O1gZOl0展示了如何用db创建一个多用户博客。