Вопрос

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.

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.

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).

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.

Это было полезно?

Решение

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.

or just json and text files.

Другие советы

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

You could try Zodb

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top