Compressing Pickle File Data Basically all we have to do, is use the bz2. BZ2File Class, instead of the standard open() function seen in regular File Handling. Likewise, you can also use the bz2. open() function, which will provide the same compression effect.