# Load file from stream This article explains how to load PDF, Word, Excel, PowerPoint documents from a stream when using GroupDocs.Parser for Python via .NET. To avoid saving a file on disk, [GroupDocs.Parser](https://products.groupdocs.com/parser/python-net) allows you to work with file streams directly. To load a document from a stream, follow these steps: 1. Open a file stream 2. Pass the opened file stream to the `Parser` class constructor The following code snippet shows how to load a file from a stream: ## Load document from file stream {{< tabs "example-1" >}} {{< tab "Python" >}} ```python from groupdocs.parser import Parser # Open the file as a binary stream with open("sample.docx", "rb") as stream: # Create an instance of Parser class with the stream with Parser(stream) as parser: # Extract text from the document text_reader = parser.get_text() if text_reader is not None: # Print the extracted text print(text_reader.read_to_end()) else: print("Text extraction isn't supported for this format") ``` {{< /tab >}} {{< tab "sample.docx" >}} {{< tab-text >}} The following sample file is used in this example: [sample.docx](https://docs.groupdocs.com/parser/python-net/_sample_files/developer-guide/advanced-usage/loading/load-file-from-stream/sample.docx) {{< /tab-text >}} {{< /tab >}} {{< tab "load-document-from-file-stream.txt" >}} ```text Supply Agreement | Harbor Lane Provisions and Northwind Coffee Roasters | Confidential Supply Agreement Harbor Lane Provisions and Northwind Coffee Roasters 1. Parties Buyer: Harbor Lane Provisions, 18 Quayside Road, Port Ellery, represented by Lena Park, Procurement Lead. Supplier: Northwind Coffee Roasters, 4 Roastery Lane, Millbrook, represented by Alex Chen. This agreement takes effect on 12 January 2026 and replaces the agreement of January 2023. [TRUNCATED] ``` [Download full output](https://docs.groupdocs.com/parser/python-net/_output_files/developer-guide/advanced-usage/loading/load-file-from-stream/example-1/load-document-from-file-stream.txt) {{< /tab >}} {{< /tabs >}} ## Load document from BytesIO stream {{< tabs "example-2" >}} {{< tab "Python" >}} ```python from groupdocs.parser import Parser from io import BytesIO # Read file into memory with open("sample.pdf", "rb") as file: file_data = file.read() # Create a BytesIO stream stream = BytesIO(file_data) # Create an instance of Parser class with the stream with Parser(stream) as parser: # Get document info doc_info = parser.get_document_info() print(f"File type: {doc_info.file_type.file_format}") print(f"Page count: {doc_info.page_count}") ``` {{< /tab >}} {{< tab "sample.pdf" >}} {{< tab-text >}} The following sample file is used in this example: [sample.pdf](https://docs.groupdocs.com/parser/python-net/_sample_files/developer-guide/advanced-usage/loading/load-file-from-stream/sample.pdf) {{< /tab-text >}} {{< /tab >}} {{< tab "load-document-from-bytesio-stream.txt" >}} ```text File type: Portable Document Format File Page count: 4 ``` [Download full output](https://docs.groupdocs.com/parser/python-net/_output_files/developer-guide/advanced-usage/loading/load-file-from-stream/example-2/load-document-from-bytesio-stream.txt) {{< /tab >}} {{< /tabs >}} ## Process uploaded file without saving This is useful for web applications where files are uploaded by users: {{< tabs "example-3" >}} {{< tab "Python" >}} ```python from groupdocs.parser import Parser from io import BytesIO def process_uploaded_file(file_content, filename): """Process an uploaded file without saving it to disk""" try: # Create a stream from the file content stream = BytesIO(file_content) # Create parser instance with Parser(stream) as parser: print(f"Processing uploaded file: {filename}") # Get document info doc_info = parser.get_document_info() print(f"File type: {doc_info.file_type.file_format}") print(f"Pages: {doc_info.page_count}") # Extract text text_reader = parser.get_text() if text_reader is not None: text = text_reader.read_to_end() return { "success": True, "filename": filename, "type": doc_info.file_type.file_format, "pages": doc_info.page_count, "text_length": len(text), "text": text } else: return { "success": False, "error": "Text extraction not supported" } except Exception as e: return { "success": False, "error": str(e) } # Example: Simulate uploaded file with open("sample.docx", "rb") as f: file_content = f.read() result = process_uploaded_file(file_content, "sample.docx") print(result) ``` {{< /tab >}} {{< tab "sample.docx" >}} {{< tab-text >}} The following sample file is used in this example: [sample.docx](https://docs.groupdocs.com/parser/python-net/_sample_files/developer-guide/advanced-usage/loading/load-file-from-stream/sample.docx) {{< /tab-text >}} {{< /tab >}} {{< tab "process-uploaded-file.txt" >}} ```text Processing uploaded file: sample.docx File type: Microsoft Word Open XML Document Pages: 2 {'success': True, 'filename': 'sample.docx', 'type': 'Microsoft Word Open XML Document', 'pages': 2, 'text_length': 2584, 'text': 'Supply Agreement | Harbor Lane Provisions and Northwind Coffee Roasters | Confidential\r\n\r\n\r\n\r\nSupply Agreement\r\nHarbor Lane Provisions and Northwind Coffee Roasters\r\n1. Parties\r\nBuyer: Harbor Lane Provisions, 18 Quayside Road, Port Ellery, represented by Lena [TRUNCATED] ``` [Download full output](https://docs.groupdocs.com/parser/python-net/_output_files/developer-guide/advanced-usage/loading/load-file-from-stream/process_uploaded_file/process-uploaded-file.txt) {{< /tab >}} {{< /tabs >}} ## More resources ### GitHub examples You may find more code examples in our GitHub repository: * [GroupDocs.Parser for Python via .NET examples](https://github.com/groupdocs-parser/GroupDocs.Parser-for-Python-via-.NET) ### Free online document parser Along with the full-featured library, we provide a free online document parser app. You are welcome to extract data from PDF, DOCX, XLSX, and more with our [Free Online Document Parser App](https://products.groupdocs.app/parser).