Skip to content

dalefwillis/node-unpickle

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unpickle Python data in Node.js

This library allows to unpickle data pickled with Python 3.5 (up to pickle prococol 4).

WARNING: Not all pickle opcodes are supported. The library was created from scratch and I only added opcodes that I encountered in my test data.

Installation

Use npm (or yarn):

npm install unpickle

Usage

const data = unpickle(<Buffer>)

The following example unpickles Django session from Redis:

import unpickle from 'unpickle'

async function getDjangoSession (sessionId) {
  const data = await redis.getAsync('django.contrib.sessions.cache' + sessionId)
  return unpickle(data)
}

Testing

git clone https://github.com/IlyaSemenov/node-unpickle.git
cd node-unpickle
yarn
npm test

How to inspect pickle in Python

s = b"\x80\x04\x95....."
import pickle; import pickletools; print(pickle.loads(s)); pickletools.dis(s)

Contributing

PRs and general feedback are welcome.

About

Unpickle Python data in Node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 100.0%