Git Product home page Git Product logo

pylib7zip's Introduction

python-lib7zip

Python bindings for 7-Zip

author

Mark Harviston <[email protected]>

version

0.1

pylib7zip is a direct binding to 7z.dll from the 7-zip project (7zip.org)

7z.dll uses Windows COM+ calling conventions without registering itself with the COM server and has an over-engineered slightly pathological OOP API.

Currently only works on Windows with Python 3.3.

This provides roughly the same functionality as lib7zip does for C++ and SevenZipSharp does for C# but with a clean Pythonic API.

Like lib7zip getting metadata and extracting files are the only operations supported, creating archives, or updating them in-place is not supported.

This is beta software and may crash if used in an unusual (or even a usual) way.

Dependencies

How To Use

By default the path to 7z.dll/7z.so will be autodetected.

import io
from lib7zip import Archive, formats
#view information on supported formats
for format in formats:
    print(format.name, ', '.join(format.extensions))

#type of archive will be autodetected
#pass in optional forceformat argument to force the use a particular format (use the name)
#pass in optional password argument to open encrypted archives.
with Archive('path_to.7z') as archive:
    #extract all items to the directory, directory will be created if it doesn't exist
    archive.extract('extract_here')

    #list all items in the archive and get their metadata
    for item in archive:
        print( item.isdir, item.path, item.crc)

    #extract a particular archive item
    # like extract, accepts a password argument, useful if different
    # items in the archive have different passwords
    archive[0].extract('extract to here.txt')

    #extract a particular archive item to a python stream object
    stream = io.BytesIO()
    archive[0].extract(stream)
    stream.getvalue()  # a bytes object containing the contents of item 0

License

This code is licensed under the BSD 2-clause license.

7-Zip is licensed under the LGPL with the exception of the code handling rar compression.

pylib7zip's People

Contributors

harvimt avatar

Watchers

James Cloos avatar Philippe Ombredanne avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.