I have a code that uses two independent packages (let's call them packageA and packageB). PackageA has a function write(outputPath: str, ...)
that writes a ".pdf" to disk of some data. PackageB includes a method called read(inputPath: str, ...)
that reads a pdf and extracts some information. The workflow makes me have to write a temporary file with the function of packageA, read it with the function of packageB and then delete it and continue working with different tools of packageB.
When I run my program on my local machine, everything works correctly. However, I need to run this code on an external server where I cannot write to disk. What are my options? I have tried to write the file to memory using the tempfile
package, but I have not succeeded because the write
function of packageA needs a string as argument where it will create the "pdf". Any help?
EDIT: here is a minimum example, the two packages are actually music21
and PyMuPdf
. In order to reproduce the example, apart from both packages you would need to install musescore, as the write
methods does an internal call to it (via os
)
import music21
import fitz
import os
piece = music21.corpus.parse('bwv66.6')
piece.write("musicxml.pdf", fp="temp.pdf")
with fitz.open("temp.pdf") as pdf:
# do some stuff with 'pdf'
pdf.save("final.pdf")
os.system("rm temp.pdf")