I would like to use the 7z DLL to append small amounts of data to one compressed file. At the moment my best guess would be uncompress the 7z file, append the data, and recompress it. Obviously, this is not a good solution performance wise, if the size of the 7z file becomes large (say 1 gb) and I want do save a new chunk every second. How could I do this in a better way?

I could use any compression format supported by the 7z DLL.

Have a look at the Python LZMA bindings (LZMA is the compression algorithm name of 7z), you should do what you want without ctypes stuff.

EDIT

To be confirmed, but a quick look at py7zlib.py shows only support for reading 7z files, not writing. However in the src dir there's a `pylzma_compressfile.c`, so maybe there's something to do.

EDIT 2

The pylzma.compressfile function seems to be there, so fine.

This is NOT MY ANSWER.

How can I use a DLL from Python

I think ctypes is the way to go.

The following example of ctypes is from actual code I've written (in Python 2.5). This has been, by far, the easiest way I've found for doing what you ask.

``````import ctypes

# Load DLL into memory.

hllDll = ctypes.WinDLL ("c:\\PComm\\ehlapi32.dll")

# Set up prototype and parameters for the desired function call.
# HLLAPI

hllApiProto = ctypes.WINFUNCTYPE (ctypes.c_int,ctypes.c_void_p,
ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p)
hllApiParams = (1, "p1", 0), (1, "p2", 0), (1, "p3",0), (1, "p4",0),

# Actually map the call ("HLLAPI(...)") to a Python name.

hllApi = hllApiProto (("HLLAPI", hllDll), hllApiParams)

# This is how you can actually call the DLL function.
# Set up the variables and call the Python name with them.

p1 = ctypes.c_int (1)
p2 = ctypes.c_char_p (sessionVar)
p3 = ctypes.c_int (1)
p4 = ctypes.c_int (0)
hllApi (ctypes.byref (p1), p2, ctypes.byref (p3), ctypes.byref (p4))
``````

The ctypes stuff has all the C-type data types (int, char, short, void*, ...) and can pass by value or reference. It can also return specific data types although my example doesn't do that (the HLL API returns values by modifying a variable passed by reference).

Top
{"ft_lang_label":"__label__en","ft_lang_prob":0.88704973,"math_prob":0.7273947,"size":2088,"snap":"2019-13-2019-22","text_gpt3_token_len":591,"char_repetition_ratio":0.12523992,"word_repetition_ratio":0.0,"special_character_ratio":0.27586207,"punctuation_ratio":0.18222222,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.96818197,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-03-27T01:26:04Z\",\"WARC-Record-ID\":\"<urn:uuid:13535f12-dea8-423b-82ad-426be5b510a3>\",\"Content-Length\":\"9621\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:01c2751a-425d-4f2b-84d9-fbf357260522>\",\"WARC-Concurrent-To\":\"<urn:uuid:2e8eeeab-3684-4722-89db-d29acc9cfab1>\",\"WARC-IP-Address\":\"104.31.73.18\",\"WARC-Target-URI\":\"http://m.dlxedu.com/m/askdetail/3/2c8896fc597c0f9496f78fc7e3a22f6f.html\",\"WARC-Payload-Digest\":\"sha1:Y5ICSYRH6AOXSKXDK6ZRXMIAQFG6PPUS\",\"WARC-Block-Digest\":\"sha1:MABCTIBIOT56INY6AUFVITIGA3J7RQBX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-13/CC-MAIN-2019-13_segments_1552912207146.96_warc_CC-MAIN-20190327000624-20190327022624-00019.warc.gz\"}"}