4 Replies - 2691 Views - Last Post: 06 December 2007 - 06:35 PM Rate Topic: -----

#1 Sharke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-December 07

Python objects and persistence

Post icon  Posted 02 December 2007 - 07:28 PM

Hi all -

I'm new to Python but not entirely new to programming, having dabbled in AMOS Basic years and years ago. OOP is new to me, although I'm definitely very happy about the idea!

What I'm trying to do is write a program to handle clients, employees and job schedules for my business. I figure it'll take me months and teach me to program along the way.

Right now I'm trying to figure out what I'm going to do about object persistence. I see that every aspect of my data could be a class - clients, employees, appointments, job types, full days, etc. And I also see that it would be useful to embed objects in each other, like embedding appointment objects within client objects, employee objects and day objects - and also having the embedded object contain its container, for instance an appointment object contains an employee object, which in turn contains an appointment object. Am I still on solid ground here, or are things getting shaky?

I can get to grips with the idea of these circular references when the objects are in memory, but what happens to references like this when I pickle them? A composite object is obviously not the complete physical representation of its definition, since this would lead to infinities when objects reference each other in a circular fashion. But what should I be thinking about when it comes to making these object structures persistent?

I've been idly looking at things like ZODB and SQLAlchemy and my head has become discombobulated. I really need to be able to store objects in a way that remembers how they are connected to each other, and I need to be able to do searches by attribute, too. I don't believe that the regular Python shelve is adequate for this, so any advice would be much appreciated!

Is This A Good Question/Topic? 0
  • +

Replies To: Python objects and persistence

#2 rockstar_  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 189
  • Joined: 16-October 06

Re: Python objects and persistence

Posted 04 December 2007 - 01:07 PM

View PostSharke, on 2 Dec, 2007 - 07:28 PM, said:

Right now I'm trying to figure out what I'm going to do about object persistence. I see that every aspect of my data could be a class - clients, employees, appointments, job types, full days, etc. And I also see that it would be useful to embed objects in each other, like embedding appointment objects within client objects, employee objects and day objects - and also having the embedded object contain its container, for instance an appointment object contains an employee object, which in turn contains an appointment object. Am I still on solid ground here, or are things getting shaky?

I can get to grips with the idea of these circular references when the objects are in memory, but what happens to references like this when I pickle them? A composite object is obviously not the complete physical representation of its definition, since this would lead to infinities when objects reference each other in a circular fashion. But what should I be thinking about when it comes to making these object structures persistent?

I've been idly looking at things like ZODB and SQLAlchemy and my head has become discombobulated. I really need to be able to store objects in a way that remembers how they are connected to each other, and I need to be able to do searches by attribute, too. I don't believe that the regular Python shelve is adequate for this, so any advice would be much appreciated!

Sharke-

Welcome to Python! I've also been wondering about a persistence layer in Python, having just recently started a job where I "get" to use Java and have found the Hibernate library to be quite helpful. SQLAlchemy is a good start. I like how it caches data, etc. However, there are many libraries that wrap SQLAlchemy, or do similar things, and might make it easier for you to come to grips with (and then it doesn't matter what you use!)

First of all, what you're talking about as far as database objects linking to eachother makes me think about the MVC pattern. Django has been overall the best representation of how to accomplish this. If you're not opposed to making your application a web application, you'll find yourself jumping in leaps and bounds. I must, however, add the disclaimer that I've been working with Django for more than a year, and am now a Django developer, do I'm just a bit biased.

Even without the whole Django stack, you can still use the models for your own application. The great thing about the models is that when set up correctly, the backend code programmatically links an object to a parent object (the many in a many to one), child objects (the one in many to one), and peer objects (in a many to many). This doesn't require any of the other Django stuff, and will help you keep track of records from a database pretty easily.

Just a suggestion. If you decide to go the SQLAlchemy route afterall and then get stuck, ping the forum again. I just finished a project using SQLAlchemy, so it's fresh in my mind.
Was This Post Helpful? 0
  • +
  • -

#3 Sharke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-December 07

Re: Python objects and persistence

Posted 04 December 2007 - 11:17 PM

I would love to have my data on a server, maybe I could even write a small GUI program for employees so they can access their own information and schedules online. Then again, I'm not sure I'm ready for internet based coding yet. Django looks really interesting though and it's definitely swimming around my head in the mix right now. I have to be careful not to get information overload as I'm still really a beginner. I am enjoying reading the documentation for SQLAlchemy, it hasn't got me yet but I might take you up on the advice once things start to get hairier. But, at least I'm making tables and the like interactively and understanding what's going on for now.

I had a look at SQLAlchemy wrappers and ended up more confused. Baby steps!

I guess my database performance requirements aren't going to be that heavy. I run a business in which clients and employees have ongoing regular weekly schedules so that all I really need to store apart from the default schedule definitions are instances of changes to those schedules - cancellations, alterations, extras etc. But at the same time, I would like to create something slick and efficient with capacity, for the learning process more than anything else and because I have a couple of other pet projects in mind which involve web applications and online databases. I guess I've gotten the bug again, after all this time... :D
Was This Post Helpful? 0
  • +
  • -

#4 rockstar_  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 189
  • Joined: 16-October 06

Re: Python objects and persistence

Posted 06 December 2007 - 04:46 PM

View PostSharke, on 4 Dec, 2007 - 11:17 PM, said:

I would love to have my data on a server, maybe I could even write a small GUI program for employees so they can access their own information and schedules online. Then again, I'm not sure I'm ready for internet based coding yet. Django looks really interesting though and it's definitely swimming around my head in the mix right now. I have to be careful not to get information overload as I'm still really a beginner. I am enjoying reading the documentation for SQLAlchemy, it hasn't got me yet but I might take you up on the advice once things start to get hairier. But, at least I'm making tables and the like interactively and understanding what's going on for now.

I had a look at SQLAlchemy wrappers and ended up more confused. Baby steps!

I guess my database performance requirements aren't going to be that heavy. I run a business in which clients and employees have ongoing regular weekly schedules so that all I really need to store apart from the default schedule definitions are instances of changes to those schedules - cancellations, alterations, extras etc. But at the same time, I would like to create something slick and efficient with capacity, for the learning process more than anything else and because I have a couple of other pet projects in mind which involve web applications and online databases. I guess I've gotten the bug again, after all this time... :D

SQLite sounds like your best bet. You could very quickly get in over what you need using something like MySQL or PostgreSQL. If you're not working with a huge database, building a Django app might actually be your best bet. It ships with a server builtin, so you don't need to mess with the lamp stack, and you could use SQLite as the database backed. Another option specifically for desktop apps is Tkinter or wxpython (using xrc or pythoncard). If your opt for SQLite, you won't have to worry about persistence, because the whole database is loaded into memory, and then flushed to file when you're done.
Was This Post Helpful? 0
  • +
  • -

#5 Sharke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-December 07

Re: Python objects and persistence

Posted 06 December 2007 - 06:35 PM

View Postrockstar_, on 6 Dec, 2007 - 04:46 PM, said:

Another option specifically for desktop apps is Tkinter or wxpython (using xrc or pythoncard). If your opt for SQLite, you won't have to worry about persistence, because the whole database is loaded into memory, and then flushed to file when you're done.


This is what happens when I'm using SQAlchemy with SQLite? It's not accessing the disk when I'm inserting or fetching?

PythonCard looks very interesting by the way....I've also been looking at Boa Constructor.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1