18

Possible Duplicate:
How to read/make sense of a PHP serialised data string in python

I'm using python to access a database which is managed by a Drupal install. The data I want to access in Drupal in saved in the database as a PHP serialized object.

Are there any pre-built python modules which can deserialize a PHP serialized object into a python object? I've done some searching and come up with nothing.

I realize I could write my own parser from scratch but I'd rather use something thats been tried and tested.

Community
  • 1
  • 1
Chris Salij
  • 3,096
  • 5
  • 26
  • 43
  • You shouldnt save any data in a language-specific format. Use a more common format, like JSON, instead (as long as its possible). – KingCrunch May 09 '11 at 10:23
  • 1
    I have no control over how the data is stored. I only need to access it. – Chris Salij May 09 '11 at 10:26
  • Seriously? You think JSON isn't language-specific? It's in the name. It's just been widely adopted. – PaulC Jun 13 '19 at 17:43
  • @PaulC: From the opening paragraph on [`json.org`](https://www.json.org/json-en.html): "JSON is a text format that is completely language independent". You're confusing its origin and name with what it actually *is*. – martineau Jun 14 '21 at 23:18

2 Answers2

33

Are you looking for phpserialize?

MattH
  • 37,273
  • 11
  • 82
  • 84
5

If you don't need object serialization (which can be compensated with associative arrays), then a faster alternative might be this: http://code.google.com/p/serek/ (it's a Python module written in C)

It's used in production servers under heavy load at my company, so I might recommend it as stable. There is no tarball available, though. So you have to grab it straight from the repository.

tymbark
  • 73
  • 5