database in python ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ajikoe@gmail.com

    #1

    database in python ?

    Hello I need to build table which need searching data which needs more
    power then dictionary or list in python, can anyone help me what kind
    of database suitable for python light and easy to learn. Is mySQL a
    nice start with python ?

    Sincerely Yours,
    Pujo

  • Klaus Alexander Seistrup

    #2
    Re: database in python ?

    ajikoe@gmail.co m wrote:
    [color=blue]
    > I need to build table which need searching data which needs more
    > power then dictionary or list in python, can anyone help me what
    > kind of database suitable for python light and easy to learn. Is
    > mySQL a nice start with python ?[/color]

    You could try SQLite for Python: <http://pysqlite.org/>.

    Cheers,

    --
    Klaus Alexander Seistrup
    Magnetic Ink, Copenhagen, Denmark
    A small ActivityPub server for friends of Magnetic Ink.

    Comment

    • jyap80@gmail.com

      #3
      Re: database in python ?

      MySQL is an excellent option is very well documented. It is also a
      defacto standard for OpenSource databases.

      You will need to install the Python module MySQLdb. -->
      http://sourceforge.net/projects/mysql-python

      There should be plenty of examples online too for using MySQLdb with
      Python.

      If you get more advanced, you can look into the SQLObject module which
      allows you to use databases in a more Pythonic objective way.

      Julian


      Comment

      • Pierre-Frédéric Caillaud

        #4
        Re: database in python ?

        [color=blue]
        > MySQL is an excellent option is very well documented. It is also a
        > defacto standard for OpenSource databases.[/color]

        MySQL sucks for anything but very very basic stuff as it supports no
        transactions, foreign keys, procedures, triggers, concurrency, etc.
        Postgresql is a lot better, free, and the psycopg adapter for Postgres is
        *very very* fast (a lot faster than the MySQL one) and it has a
        dictfetchall() method which is worth its weight in donuts !

        Comment

        • Ola Natvig

          #5
          Re: database in python ?

          Pierre-Frédéric Caillaud wrote:[color=blue]
          > [color=green]
          >> MySQL is an excellent option is very well documented. It is also a
          >> defacto standard for OpenSource databases.[/color]
          >
          >
          > MySQL sucks for anything but very very basic stuff as it supports
          > no transactions, foreign keys, procedures, triggers, concurrency, etc.
          > Postgresql is a lot better, free, and the psycopg adapter for
          > Postgres is *very very* fast (a lot faster than the MySQL one) and it
          > has a dictfetchall() method which is worth its weight in donuts ![/color]

          MySQL has support for transactions and foreign keys in it's InnoDB
          engine. In 5.0 it supports views procedures. Some people seems to hate
          MySQL :-) but a whole lot of other people like it a lot.

          The thing is, if you don't spesificaly state that you want triggers,
          concurrency and procedures I guess that your needs are quite basic.

          However you won't be be disappointed with either MySQL or postgree in
          your trunk :)

          ola

          --
          --------------------------------------
          Ola Natvig <ola.natvig@inf osense.no>
          infoSense AS / development

          Comment

          • elbertlev@hotmail.com

            #6
            Re: database in python ?

            aji...@gmail.co m wrote:[color=blue]
            > I need to build table which need searching data which needs more
            > power then dictionary or list in python, can anyone help me what
            > kind of database suitable for python light and easy to learn. Is
            > mySQL a nice start with python ?[/color]

            It depends... mySQL is fine for more or less data centric applications
            with many tables.

            When I need SQL search power, but the number of tables/records is small
            enough gadfly is the best bet. Contact database, CD catalog, extended
            configuration data are proper examples. In such cases, gadfly is by far
            faster, then "normal" relational databases.

            Comment

            • Roy Smith

              #7
              Re: database in python ?

              In article <1113197530.990 898.46130@z14g2 000cwz.googlegr oups.com>,
              "ajikoe@gmail.c om" <ajikoe@gmail.c om> wrote:
              [color=blue]
              > Hello I need to build table which need searching data which needs more
              > power then dictionary or list in python, can anyone help me what kind
              > of database suitable for python light and easy to learn. Is mySQL a
              > nice start with python ?
              >
              > Sincerely Yours,
              > Pujo[/color]

              MySQL lacks some of the more advanced features of commercial SQL databases
              like Oracle or Sybase, but other than that, it's an excellent and very
              popular choice.

              It's free, easy to install, runs on many platforms and has interfaces to
              many languages (including Python). It's also been around a long time and
              used on many large-scale projects, so you can have confidence that it's
              stable. It's also well documented, both with on-line material from the
              makers, and from third party publishers (I like the O'Reily book).

              Comment

              • Fred Pacquier

                #8
                Re: database in python ?

                "ajikoe@gmail.c om" <ajikoe@gmail.c om> said :
                [color=blue]
                > Hello I need to build table which need searching data which needs more
                > power then dictionary or list in python, can anyone help me what kind
                > of database suitable for python light and easy to learn. Is mySQL a
                > nice start with python ?[/color]

                There are a number of separate database engines with a python interface, as
                others in the thread have shown. However, if you mostly work with one table
                at a time, as you seem to imply, then you might have a look a Kirbybase :
                it's a single python module, and databases don't come any lighter or easier
                than that :)

                --
                YAFAP : http://www.multimania.com/fredp/

                Comment

                • Pierre-Frédéric Caillaud

                  #9
                  Re: database in python ?


                  If you want Simple you can use the following piece of code.
                  It won't work if you have a million records, but it's a nice intelligent
                  flatfile storage with a select where + order by and limit emulator.

                  # ############### ############### ############### ############

                  class ListMgr( object ):
                  def __init__( self, klass, filename ):
                  self.filename = filename
                  self.klass = klass
                  self.load()

                  def load( self ):
                  try:
                  self.contents = pickle.load( open( self.filename ))
                  print "Loaded %d items %s in %s" % (len(self.conte nts), self.klass,
                  type(self))
                  except IOError:
                  print "Creating new contents for", type(self)
                  self.contents = {}
                  self.save()

                  if self.contents:
                  self.insert_id = max( self.contents.k eys() ) +1
                  else:
                  self.insert_id = 1

                  def save( self ):
                  pickle.dump( self.contents, open( self.filename+' .tmp', 'w' ) )
                  os.rename( self.filename+' .tmp', self.filename )
                  print "Saved %d items %s in %s" % (len(self.conte nts), self.klass,
                  type(self))

                  def new( self, **params ):
                  return self.klass( **params )

                  def insert( self, obj ):
                  assert not hasattr( obj, 'id' ) or obj.id is None
                  obj.id = self.insert_id
                  self.insert_id += 1
                  self.contents[obj.id] = obj

                  def update( self, obj ):
                  assert obj.id is not None
                  self.contents[obj.id] = obj

                  def select( self, id ):
                  return self.contents[ id ]

                  def delete( self, id ):
                  del self.contents[ id ]

                  def count( self ):
                  return len( self.contents )

                  # where is a lambda function, order_by is a cmp function, limit is a slice
                  def select_multiple ( self, where=None, order_by=None ):
                  if where:
                  c = filter( where, self.contents.i tervalues() )
                  else:
                  c = self.contents.v alues()
                  if order_by:
                  c.sort( order_by )
                  return c

                  # ############### ############### ############### ############

                  class ListEntry( object ):
                  def __init__( self, **params ):
                  self.__dict__ = dict.fromkeys( self.get_fields () )
                  self.__dict__.u pdate( params )

                  def get_fields( self ):
                  return ()

                  def display( self ):
                  print '-'*40
                  if hasattr( self, 'id' ):
                  print "id :",self.id
                  for k in self.get_fields ():
                  print k," :",getattr(self ,k)
                  print

                  # ############### ############### ############### ############

                  class AddressBookEntr y( ListEntry ):
                  def get_fields( self ):
                  return 'name', 'address', 'zipcode', 'city', 'country', 'phone'
                  get_fields = classmethod( get_fields )

                  class AddressBook( ListMgr ):
                  def __init__( self, fname ):
                  super( AddressBook, self ).__init__( AddressBookEntr y, fname )



                  Comment

                  • R. C. James Harlow

                    #10
                    Re: database in python ?

                    On Monday 11 April 2005 11:01, Pierre-Frédéric Caillaud wrote:[color=blue]
                    > psycopg ... has a dictfetchall() method which is worth its weight in
                    > donuts ! [/color]

                    It's very simple to write one for MySQLdb:

                    def dictfetchall(cu rsor):
                    '''Takes a MySQLdb cursor and returns the rows as dictionaries.'' '
                    col_names = [ d[0] for d in cursor.descript ion ]
                    return [ dict(zip(col_na mes, row)) for row in cur.fetchall() ]

                    In truth, although postgres has more features, MySQL is probably better for
                    someone who is just starting to use databases to develop for: the chances are
                    higher that anyone using their code will have MySQL than Postgres, and they
                    aren't going to need the features that Postgresql has that MySQL doesn't.
                    IMO, this has changed since only a year or two ago, when MySQL didn't support
                    foreign-key constraints.

                    -----BEGIN PGP SIGNATURE-----
                    Version: GnuPG v1.2.4 (GNU/Linux)

                    iD8DBQBCWoacY6W 16wIJgxQRAnbTAJ 9g+gSEc9/fKBbVVuAKPaKq0B aPrwCghAcX
                    y6TFDJYn6AzIMmn Pbc1EMrM=
                    =b4eV
                    -----END PGP SIGNATURE-----

                    Comment

                    • Andy Dustman

                      #11
                      Re: database in python ?

                      Pierre-Frédéric Caillaud wrote:[color=blue][color=green]
                      > > MySQL is an excellent option is very well documented. It is also a
                      > > defacto standard for OpenSource databases.[/color]
                      >
                      > MySQL sucks for anything but very very basic stuff as it supports no[/color]
                      [color=blue]
                      > transactions,[/color]

                      Transactions available since 3.23.17 (June 2000)
                      [color=blue]
                      > foreign keys,[/color]

                      Foreign keys available since 3.23.44 (Oct 2001)
                      [color=blue]
                      > procedures,[/color]

                      Stored procedures available since 5.0 (5.0.3 is the current beta)
                      [color=blue]
                      > triggers,[/color]

                      Triggers available since 5.0.2
                      [color=blue]
                      > concurrency, etc.[/color]

                      Who knows what *this* means. Anyone who thinks MySQL can't handle
                      multiple concurrent connections is clearly delusional or ignorant.
                      [color=blue]
                      > Postgresql is a lot better, free, and the psycopg adapter for[/color]
                      Postgres is[color=blue]
                      > *very very* fast (a lot faster than the MySQL one) and it has a
                      > dictfetchall() method which is worth its weight in donuts ![/color]

                      Postgresql is also a fine database. But note that MySQLdb (the Python
                      adapter) also has an equivalent mechanism for returning rows as
                      dictionaries. As for speed: I don't do any benchmarking, but there
                      should be no substantial speed differences between the two interfaces.

                      Comment

                      • Roel Schroeven

                        #12
                        Re: database in python ?

                        Ola Natvig wrote:
                        [color=blue]
                        > MySQL has support for transactions and foreign keys in it's InnoDB
                        > engine. In 5.0 it supports views procedures. Some people seems to hate
                        > MySQL :-) but a whole lot of other people like it a lot.[/color]

                        There are other problems, such as failing silently in many
                        circumstances, as documented on http://sql-info.de/mysql/gotchas.html.
                        I'm not saying these issues should make one avoid MySQL at all costs,
                        but I think one should at least be aware of them.

                        --
                        If I have been able to see further, it was only because I stood
                        on the shoulders of giants. -- Isaac Newton

                        Roel Schroeven

                        Comment

                        • Steve Holden

                          #13
                          Re: database in python ?

                          Pierre-Frédéric Caillaud wrote:[color=blue]
                          >[color=green]
                          >> MySQL is an excellent option is very well documented. It is also a
                          >> defacto standard for OpenSource databases.[/color]
                          >
                          >
                          > MySQL sucks for anything but very very basic stuff as it supports
                          > no transactions, foreign keys, procedures, triggers, concurrency, etc.
                          > Postgresql is a lot better, free, and the psycopg adapter for
                          > Postgres is *very very* fast (a lot faster than the MySQL one) and it
                          > has a dictfetchall() method which is worth its weight in donuts ![/color]

                          While I wouldn't necessarily disagree with your assessment of the
                          relative merits of those two databases your information about MySQL is
                          somewhat out of date - for example, it has supported transactions for
                          almost two years now.

                          regards
                          Steve
                          --
                          Steve Holden +1 703 861 4237 +1 800 494 3119
                          Holden Web LLC http://www.holdenweb.com/
                          Python Web Programming http://pydish.holdenweb.com/

                          Comment

                          • Uwe Grauer

                            #14
                            Re: database in python ?

                            Pierre-Frédéric Caillaud wrote:[color=blue]
                            >[color=green]
                            >> MySQL is an excellent option is very well documented. It is also a
                            >> defacto standard for OpenSource databases.[/color]
                            >
                            >
                            > MySQL sucks for anything but very very basic stuff as it supports
                            > no transactions, foreign keys, procedures, triggers, concurrency, etc.
                            > Postgresql is a lot better, free, and the psycopg adapter for
                            > Postgres is *very very* fast (a lot faster than the MySQL one) and it
                            > has a dictfetchall() method which is worth its weight in donuts ![/color]

                            Yes, Postgresql is a lot better than MySQL but take a look at Firebird
                            to see how easy a full featured db-System could be.
                            Use kinterbasdb from Sourceforge to get Firebird into Python.

                            Uwe

                            Comment

                            • Buck Nuggets

                              #15
                              Re: database in python ?

                              > In truth, although postgres has more features, MySQL is probably[color=blue]
                              > better for someone who is just starting to use databases to develop
                              > for: the chances are higher that anyone using their code will have
                              > MySQL than Postgres, and they aren't going to need the features
                              > that Postgresql has that MySQL doesn't. IMO, this has changed
                              > since only a year or two ago, when MySQL didn't support foreign-key
                              > constraints.[/color]

                              mysql does deserve serious consideration now that it supports
                              transactions. However, keep in mind:

                              1. mysql doesn't support transactions - one of its io layers (innodb)
                              does. If you're hoping to get your application hosted you will find
                              that most mysql installations don't support innodb. And due to the
                              bugs in mysql, when you attempt to create a transaction-safe table in
                              mysql if innodb isn't available it will just silently create it in
                              myisam, and your transactions will be silently ignored.

                              2. mysql is still missing quite a few database basics - views are the
                              most amazing omission, but the list also includes triggers and stored
                              procedures as well. Although most of these features are included in
                              the new beta, they aren't yet available in production.

                              3. mysql has an enormous number of non-standard features such as
                              comment formatting, how nulls work, concatenation operator, etc. This
                              means that you'll learn non-standard sql, and most likely write
                              non-portable sql.

                              4. additionally, mysql has a peculiar set of bugs - in which the
                              database will change your data and report no exception. These bugs
                              were probably a reflection of mysql's marketing message that the
                              database should do nothing but persist data, and data quality was the
                              responsibility of the application. This self-serving message appears
                              to have been dropped now that they are catching up with other products,
                              but there's a legacy of cruft that still remains. Examples of these
                              errors include: silent truncation of strings to fit max varchar
                              length, allows invalid dates, truncation of numeric data to fit max
                              numeric values, etc.

                              5. cost: mysql isn't expensive, but it isn't free either. Whether or
                              not you get to use it for free depends on how you interpret their
                              licensing info and faq. MySQL's recommendation if you're confused (and
                              many are) is to license the product or call one of their reps.

                              Bottomline - mysql has a lot of marketshare, is improving, and I'm sure
                              that it'll eventually be a credible product. But right now it's has a
                              wide range of inexcusable problems.

                              More info at http://sql-info.de/mysql/gotchas.html

                              buck

                              Comment

                              Working...