<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pasham Sathwik reddy on Medium]]></title>
        <description><![CDATA[Stories by Pasham Sathwik reddy on Medium]]></description>
        <link>https://medium.com/@pashamsathwikreddy?source=rss-5db5764d2258------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*p_RIBXyCuRzMnZ2l43rmXA.jpeg</url>
            <title>Stories by Pasham Sathwik reddy on Medium</title>
            <link>https://medium.com/@pashamsathwikreddy?source=rss-5db5764d2258------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 23:06:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pashamsathwikreddy/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[LLM Apps in Minutes with Langchain!]]></title>
            <link>https://medium.com/@pashamsathwikreddy/llm-apps-in-minutes-with-langchain-4fd2c4bd831a?source=rss-5db5764d2258------2</link>
            <guid isPermaLink="false">https://medium.com/p/4fd2c4bd831a</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[youtube]]></category>
            <category><![CDATA[langchain]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Pasham Sathwik reddy]]></dc:creator>
            <pubDate>Wed, 18 Sep 2024 15:20:48 GMT</pubDate>
            <atom:updated>2024-09-18T15:20:48.044Z</atom:updated>
            <content:encoded><![CDATA[<p>Langchain : LLM App toolkit</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BMXBbi84cRz21FgLLCOe2w.jpeg" /><figcaption>Image Generated using Gemini</figcaption></figure><p>This is the era of the LLMs,</p><p>You all witnessed the capabilities of LLM from generating human like text to document querying and information extraction</p><p>But is that really all LLMs can do?</p><p>Not even close!</p><p>Imagine <strong>harnessing the power of an LLM</strong> to create your <strong>own customized applications</strong> — whether it’s a chatbot or a specialized tool tailored to your needs.</p><p>So, thinking about turning your living room into an LLM lab?</p><p>No need! Just grab an existing LLM, plug it into your project</p><p>voilà — your app’s got all the brainpower it needs.</p><p><strong><em>So, how exactly can we build apps in minutes?</em></strong></p><p>The answer is <strong>LangChain.</strong></p><p><strong>Don’t believe it?</strong> Let me show you how with a simple use case!</p><p>Ever wished you could <strong>skip the long YouTube videos</strong> and still get the <strong>main takeaways?</strong></p><p>With LangChain, you can! In this article I’ll show you how to build a <strong>Python app that summarizes youtube video</strong>, saving you time and effort.</p><p>And stick around — I’ll share the best <strong>FREE Awesome resources</strong> to help you master LangChain <strong>by the end!</strong></p><p>Langchain is a <strong>open-source framework </strong>designed specifically for <strong>building AI applications with LLMs</strong></p><p>It is like a <strong>toolbox</strong> with <strong>ready-to-use tools</strong> to <strong>add LLMs to your apps!</strong></p><p>Much like other Python libraries such as NumPy and Pandas, LangChain is a <strong>specialized library</strong> for creating applications that <strong>leverage LLMs.</strong></p><p><strong>Ready to build? Let’s dive in!!</strong></p><h3>Why Langchain?</h3><p>You might be wondering, weren’t LLM apps developed before LangChain?</p><p>Absolutely, many tools and frameworks have been around for a while</p><p><strong><em>So, what makes LangChain stand out?</em></strong></p><p>It’s not just about interacting with LLMs but about how<strong> seamlessly </strong>and <strong>flexibly</strong> you can <strong>build</strong> and <strong>customize your applications.</strong></p><p>To clarify, here’s a comparison of LangChain, OpenAI API, and Hugging Face Transformers for application development.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*D2-VCLBbArac3cHgkGRIMw.png" /></figure><p>LangChain’s innovative approach makes it a standout choice for building AI applications.</p><p>To start building with LangChain, it’s important to understand its key components. Here’s a quick look :</p><h3>Key Components of Langchain:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*CqkEfogukdePcxVkNRbzpw.png" /></figure><p><strong>Chains :</strong> These are a <strong>series of steps</strong> that take an input, process it through each stage, and produce an output.</p><p>Think of it like a sequence of small tasks where <strong>the output of one step becomes the input for the next.</strong></p><p><strong>Agents</strong>: Think of it a like <strong>decision-makers</strong> that figure out which steps to take and in what order</p><p>They can adapt to different situations by analyzing the input and deciding the best course of action on the go.</p><p>In Chains, a sequence of actions is hardcoded.</p><p>In <strong>Agents</strong>, a language model is used as a <strong>reasoning engine</strong> to determine which actions to take and in which order.</p><p><strong>LLMs:</strong> Langchain supports a variety of LLMs, including OpenAI’s GPT-3, Hugging Face’s Transformers, and Google AI’s PaLM</p><p>This flexibility allows developers to choose the best model for their specific needs.</p><p><strong>Tools and Plugins</strong>: These are additional modules or extensions that enhances Langchain’s functionality.</p><p>Tools might include things like APIs for external services, data processing utilities, or integrations with other systems.</p><p>Plugins allow LangChain to interact with a variety of resources and enhance its versatility.</p><p><strong>Retrieval-Augmented Generation (RAG)</strong>: This is a framework within LangChain that combines retrieval and generation components. It involves:</p><ul><li><strong>Retrieval</strong>: Fetching relevant information or documents based on a query.</li><li><strong>Generation</strong>: Using an LLM to generate responses or content based on the retrieved information.</li></ul><p>This combination helps produce more accurate and contextually relevant responses.</p><p><strong>Prompts:</strong> Prompts are the <strong>instructions to LLM </strong>to <strong>guide to the specific goal.</strong></p><p>Prompts help the model understand what you want it to do or talk about, influencing how it generates text or answer</p><p>Curious about <strong>mastering prompts?</strong> Check out my previous article for all the insights!</p><p>This is the article👉:<a href="https://medium.com/@pashamsathwikreddy/prompt-engineering-101-understanding-the-basics-60702b601116"><strong>Prompt Engineering 101 : Understanding the Basics</strong></a></p><p>The theory is set — let’s start building the app!</p><h3>Setting up your Environment</h3><h4>Install Python</h4><p>If you donot have python installed,you can download it from the <a href="https://www.python.org/downloads/">official website</a>.Make sure you’re using Python 3.7 or later.</p><h4>Create a Project Directory</h4><p>Open the terminal on your computer and type below commands</p><pre>mkdir langchain_project<br>cd langchain_project<br>type nul &gt; .env</pre><p>or You can create the folder manually and empty .env file</p><h4>Create a virtual environment</h4><p>It’s a good practice to use a virtual environment to manage yout project’s dependencies</p><pre>python -m venv my_env<br>my_env\Scripts\activate #on mac or linux use command : source my_env/bin/activate</pre><h4>Install Langchain</h4><pre>pip install langchain</pre><h4>Choose an LLM Provider</h4><p>Choose an LLM provider like OpenAI, Hugging Face, Google AI, or Meta LLAMA.</p><p>To use <strong>Meta’s LLaMA model</strong>, try Groq.(That’s what I’m using for this project.)</p><p>It’s a cloud-based service offering powerful AI without hardware concerns.</p><p>Simply <a href="https://console.groq.com/login"><strong>Sign up / Login</strong></a><strong> </strong>and <a href="https://console.groq.com/keys"><strong>Generate an API key</strong></a><strong> </strong>to get started with Groq</p><p><strong><em>Please save and securely store your API key, as it will not be visible again.</em></strong></p><p>Add your API key in .env file</p><p><strong>GROQ_API_KEY</strong> = <strong>your_groq_api_key_here</strong></p><p>With your environment set up, you’re ready to build any project in it!</p><h3>Building a Youtube Summarizer</h3><h4>Install the necessary libraries</h4><pre>pip install langchain_community langchain_groq langchain_text_splitters tiktoken dotenv pytube youtube_transcript_api<br>&#39;&#39;&#39; Libraries installed using above command:<br>langchain_community<br>langchain_groq <br>langchain_text_splitters <br>tiktoken<br>dotenv <br>pytube<br>youtube_transcript_api<br>&#39;&#39;&#39;<br></pre><p>If you want to use other models</p><h4>Import the libraries</h4><pre>from langchain_community.document_loaders import YoutubeLoader<br>from langchain_groq import ChatGroq <br>from langchain.prompts import ChatPromptTemplate<br>from langchain_text_splitters import TokenTextSplitter<br>from dotenv import load_dotenv<br><br>load_dotenv() # load the API keys using this</pre><h4>Initialize the LLM</h4><pre># Initialize the LLM with Groq<br>model = ChatGroq(<br>    model=&#39;llama-3.1-70b-versatile&#39;,<br>    stop_sequences=[&quot;&lt;|endoftext|&gt;&quot;]<br>)</pre><h4>Load and prepare the data</h4><pre>url = &#39;&#39;  # Replace with your YouTube URL<br><br>text_content = &#39;&#39;<br>if &quot;youtube.com&quot; in url:<br>    loader = YoutubeLoader.from_youtube_https://medium.com/url(url)<br>    data = loader.load()<br>    text_content = data[0].page_content<br>else:<br>    raise ValueError(&quot;Invalid YouTube URL&quot;)</pre><h4>Define the Prompt Template</h4><p>A <strong>prompt template</strong> is a predefined structure or format used to generate input prompts for a language model. It includes placeholders (like {text}) that are replaced with specific content when creating the final prompt.</p><pre># Create a prompt template for summarizing text<br># The {text} part will be replaced with the actual text we want to summarize.<br>template = &quot;Write a concise summary of the following text: {text}&quot;<br><br># ChatPromptTemplate helps in creating and managing prompts for the language model.<br># It takes the template and sets it up to be used with real text content.<br>prompt_template = ChatPromptTemplate.from_template(template)</pre><h4>Create Summarization chain</h4><pre>chain = prompt_template | model</pre><p>The | (<strong>pipe symbol</strong>) is used to create a chain between prompt_template and model</p><p>This means the output from prompt_template will be used as input to the model</p><h4>Split Text and Generate Summary</h4><p>But wait.. Why we need to split the text?</p><p>Even the best language models have a token limit—ours is 20k tokens.</p><p>If your text is longer than that, trying to summarize it all at once can be a bit too much!</p><p>Splitting the text into smaller chunks helps the model handle each piece with ease and keeps things running smoothly.</p><pre># Initialize the text splitter to handle large text<br>text_splitter = TokenTextSplitter(chunk_size=18000, chunk_overlap=0)<br><br># Split the long text into smaller chunks<br>texts = text_splitter.split_text(text_content)<br><br># Generate summaries for each chunk<br>summaries = []<br>for t in texts:<br>    summaries.append(chain.invoke({&#39;text&#39;: t}).content)<br># The `invoke` method sends the input (in this case, the text chunk) through the chain,<br># which applies the prompt template to format the text and then uses the model to generate a response.<br># and `.content` extracts the actual text of the generated summary from this result.</pre><h4>Combine all the summaries</h4><pre># Combine all summaries into a final result<br>final_summary = &quot; &quot;.join(summaries)<br>print(final_summary)</pre><p>Voilà — your YouTube summarizer is all set and ready to go!</p><h3>Where to go from here?</h3><p>Try it yourself with your<strong> favorite YouTube video.</strong></p><p>You can even consider pushing this project to GitHub to showcase your work and share it with the community.</p><p>Summarization is just one way to use the vast capabilities of Langchain</p><p>Now that you’ve set up your first LangChain project, try experimenting with other LLMs or chains to see what you can build!</p><p>To dive deeper into LangChain, <strong>consider these</strong> <strong>resources</strong>:</p><p><a href="https://www.youtube.com/watch?v=yF9kGESAi3M"><strong>Langchain master class for beginners 2024</strong></a> : The best youtube video available , offering excellent explanations and insights.</p><p>If you’re looking to dive into <strong>more projects</strong>, check out the below <strong>github repositories:</strong></p><ul><li><a href="https://github.com/curiousily/Get-Things-Done-with-Prompt-Engineering-and-LangChain"><strong>Get-Things-Done-with-Prompt-Engineering-and-LangChain</strong></a></li><li><a href="https://github.com/jayeshironside/Langchain_Projects"><strong>Langchain Projects</strong></a></li></ul><p><a href="https://python.langchain.com/v0.2/docs/introduction/"><strong>LangChain Documentation</strong></a>: Essential for <strong>detailed reference</strong> and <strong>further learning.</strong></p><p>I relied on the resources mentioned above as references.</p><p>If you have any questions or comments, feel free to write in the comments section.</p><p><em>Thanks for reading! If you like the article, make sure to </em><strong><em>clap 👏,</em></strong><em> and let’s </em><strong><em>connect on</em></strong><em> </em><a href="https://www.linkedin.com/in/pashamsathwikreddy/"><strong><em>LinkedIn</em></strong></a><em> and </em><strong><em>follow me on </em></strong><a href="https://medium.com/@pashamsathwikreddy"><strong><em>Medium</em></strong></a><em> to stay updated with my new articles.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4fd2c4bd831a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prompt Engineering 101: Understanding the Basics]]></title>
            <link>https://medium.com/@pashamsathwikreddy/prompt-engineering-101-understanding-the-basics-60702b601116?source=rss-5db5764d2258------2</link>
            <guid isPermaLink="false">https://medium.com/p/60702b601116</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[chatgpt]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Pasham Sathwik reddy]]></dc:creator>
            <pubDate>Fri, 23 Aug 2024 14:06:48 GMT</pubDate>
            <atom:updated>2024-08-23T14:06:48.794Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dwCy40M0O4NE1uCI" /><figcaption>Photo by <a href="https://unsplash.com/@dkoi?utm_source=medium&amp;utm_medium=referral">D koi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Prompt Engineering 101 : Understanding the Basics</h3><p>Ever feel like you struggling with ChatGPT to get some information,but your friend just types in a question and BAM! Perfect answer?</p><p>It’s all about knowing how to ask the right questions — that’s the magic of <strong>Prompt engineering.</strong></p><p>Let’s uncover the magic behind crafting effective prompts for seamless interactions with LLMs</p><h3>What are LLMs?</h3><p><strong>LLM stands for Large Language model.Think of LLM as a big computer program designed to understand human language and generate responses that mimic human conversation</strong>.</p><p>These models can perform various tasks,including:</p><ul><li>Language Translation</li><li>Text Classification</li><li>Answering Questions</li><li>Summarization</li></ul><h3>What are Prompts?</h3><p><strong>Prompts are the instructions to LLM to guide to the specific goal.</strong></p><p>They are like GPS to the driver who needs to reach a destination in an unfamiliar region.</p><p>Quality of your results depend on how well your prompt is crafted.</p><p>You can enhance the quality of a prompt by adding context,examples and specific instructions.</p><h3>Components of Prompts</h3><p>A well crafted prompt typically includes these components:</p><ul><li>Instruction: A clear task or direction for the model to follow.</li><li>Context: External details or background information that guide the model to provide better responses.</li><li>Input Data: The question or input you want the model to generate a response for.</li><li>Output Indicator: The desired type or format of the output</li></ul><h3>Crafting a quality prompt</h3><p>Creating a prompt involves an iterative approach. You start with a basic prompt and then experiment by tweaking the prompt to achieve the desired results.</p><p>You should try using different keywords, data, and contexts in tweaking the prompt.</p><h3>Example:Unerstanding Prompts</h3><p>Imagine I’m eager to learn about prompt engineering, so I turn to ChatGPT for guidance.</p><p><strong>Initial Prompt </strong>: What is prompt engineering?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pfL9JyJeV6e1a5pV.png" /></figure><p>As a beginner, understanding this can be quite challenging, so I adjust the prompt accordingly.</p><p><strong>Revised Prompt</strong> : I am a beginner to language models. Could you explain prompt engineering to me in the simplest way possible, using examples?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BxSDgQosVsZU3pOk" /></figure><p>Here, I’ve provided context about myself,indicated my difficulty in understanding complex concepts and requested examples.</p><p>This alteration completely shifted the approach to addressing the topic.</p><p>In any prompt, the most important element is <strong>CONTEXT</strong>. It helps the model understand more about the query by providing background information.</p><p>As seen in the example above, providing context about my skill level totally changed the way the question was answered</p><h3><strong>Types of Prompting</strong></h3><p>The type of prompt you use can significantly influence the outcome. Here are some common prompting techniques:</p><p><strong>Zero Short Prompting:</strong></p><p>This is simple prompting in which the user tries to interact with the model without any examples.</p><p>User simply instructs the model to perform the task</p><p>Zero-shot is more flexible as it requires no additional data preparation</p><p>Use zero-shot for quick tasks where a perfect answer isn’t crucial.</p><p><strong>Example :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3KpoW8VKzUFYF_hbfDwSpg.png" /></figure><p><strong>Few Short Prompting:</strong></p><p>In this technique, the user provides the model with a few examples of the task to be performed.</p><p>It requires additional data preparation.</p><p>Can be fine tuned for specific tasks.</p><p><strong>Example :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fdTxS7ONjTg798iIajpuwQ.png" /></figure><p><strong>Chain of Thought Prompting:</strong></p><p>This technique involves encouraging the model to show its reasoning process by providing intermediate steps for the response.</p><p>It helps the model provide a more detailed and reasoned answer.</p><p>Same does by COT</p><ul><li><strong>Standard Prompting (like asking a question):</strong> This is like asking a student for the answer to a math problem without showing their work.</li><li><strong>CoT Prompting:</strong> This is like asking a student to show their work and explain each step they took to arrive at the answer.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*va6y4i-M0sKTnrDBJmkRhg.png" /><figcaption>Image Source: <a href="https://arxiv.org/abs/2201.11903">Wei et al. (2022)</a></figcaption></figure><p><strong>Example :</strong></p><p>Imagine you are solving a maths problem,you directly blurt the answer.Instead you break down into steps by giving reasoning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KECuOcaKVP4jfENwJxFqmA.png" /></figure><p>CoT prompting is a powerful tool for helping LLMs reason and explain their thought process</p><p><strong>Use Cases:</strong></p><p><strong>Classification:</strong></p><p>It refers to the task of assigning a text or image or video to a predefined labels.In this LLMs first understands the text,Match to categories and assign the label.</p><p><strong>Example :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NA8gubi7ddd-wVpHao6qSA.png" /></figure><p><strong>Summarization:</strong></p><p>It is the task of creating a shorter version of a text document that captures the <strong>main ideas and essential information</strong></p><p><strong>Example :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NFsrSaj092CXRDa3nhQhvQ.png" /></figure><h3>Conclusion:</h3><p>By crafting well-defined prompts,you can effectively communicate tasks and achieve desired outcomes.</p><p>Experiement with different prompting techniques and iterate to find the most suitable approach for your needs.</p><p>If you’re interested in delving deeper into the world of prompt engineering, you might want to explore the website <a href="https://www.promptingguide.ai/">https://www.promptingguide.ai/</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60702b601116" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking Text from PDFs with Python: My Exploration]]></title>
            <link>https://medium.com/@pashamsathwikreddy/unlocking-text-from-pdfs-with-python-my-exploration-010cc2c8cab3?source=rss-5db5764d2258------2</link>
            <guid isPermaLink="false">https://medium.com/p/010cc2c8cab3</guid>
            <category><![CDATA[pdf-extraction]]></category>
            <category><![CDATA[data-extraction]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[text-extraction]]></category>
            <category><![CDATA[pymupdf]]></category>
            <dc:creator><![CDATA[Pasham Sathwik reddy]]></dc:creator>
            <pubDate>Mon, 17 Jun 2024 09:07:39 GMT</pubDate>
            <atom:updated>2026-08-11T12:28:15.086Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*I1NNtFRU4cByUEuw" /><figcaption>Photo by <a href="https://unsplash.com/@homajob?utm_source=medium&amp;utm_medium=referral">Scott Graham</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Ever found yourself stuck trying to pull information from a pile of PDFs for a project?</p><p>I’ve been there too!</p><p>Imagine this: you are tasked with a text extraction from a pile of PDFs for crucial project work.</p><p>I thought just copying all the text from the PDF and pasting it into a text file would be a simple solution.</p><p>Sounds simple,right?</p><p>But here’s the catch: I quickly realized that the data wasn’t as structured as I’d hoped. Some information was missing due to various font formats used in the PDFs, and to make matters worse, text inside images was getting copied too. While this approach worked fine for simple PDFs, it turned into a complete mess with more complex ones.</p><p>Being a Python enthusiast, I decided to explore different libraries for data extraction from PDFs. That’s when I discovered that handling PDF data extraction is a complex task in the world of data processing.</p><p>After some research, I discovered several prominent libraries designed for PDF data extraction:</p><ul><li>PyPDF2</li><li>Pikepdf</li><li>Pdfrw</li><li>Pdfminer</li><li>pdfminer.six</li><li>Camelot</li><li>Tabula-py</li><li>Pymupdf</li></ul><p>With numerous options, I felt overwhelmed choosing the right library.</p><p>When selecting a library for PDF text extraction, several factors come into play, such as :</p><ul><li>Document complexity</li><li>output format</li><li>ease of use</li><li>Accuracy</li><li>performance</li><li>community</li><li>features</li></ul><p>Each library has its strengths and weaknesses.</p><p>Skip the tedious documentation dive; I’ve already tackled the research and laid out the results for you:</p><ul><li><strong>PyMuPDF</strong>: High-performance, image extraction, metadata retrieval,accuracy,Supports all type of docs,.</li><li><strong>Pikepdf</strong>: PDF manipulation, high-performance, Python interface, accuracy, advanced features.</li><li><strong>PyPDF2</strong>: Simplicity, basic tasks, easy-to-use,performance.</li><li><strong>pdfminer.six</strong>: Flexibility, Python 2/3 support, complex structures,community support.</li><li><strong>pdfrw</strong>: Supports PDF format, basic tasks, metadata retrieval, accuracy, and image extraction.</li><li><strong>pdfplumber</strong>: Accurate text extraction, page layout analysis, and text conversion from PDF documents.</li><li><strong>PDFMiner</strong>: Advanced control, complex structures, precise extraction,accuracy.</li><li><strong>Camelot &amp; Tabula-py</strong>: Accurate table extraction, structured data,ease of use.</li></ul><p>For extensive feature comparison you can refer this link:</p><p><a href="https://pymupdf.readthedocs.io/en/latest/about.html">https://pymupdf.readthedocs.io/en/latest/about.html</a></p><h3>Why I used PyMuPDF?</h3><p><strong>PyMuPDF</strong> is a high-performance <strong>Python</strong> library for data extraction, analysis, conversion &amp; manipulation of <strong>PDF</strong> (and other) documents.</p><p>My requirements are</p><ul><li>I want to extract text from PDFs, no matter their format.</li><li>Then, I want to change that text into different formats like HTML, JSON, dictionaries, etc., so I can analyze the data.</li></ul><p>After careful comparison, it closely aligns with my requirements.</p><p>PyMuPDF can handle more types of documents compared to other libraries. It not only extracts text from PDFs but also provides diverse metadata in different formats.</p><h3>Set up and installation:</h3><p>Follow the below-given instructions to create a virtual environment and install the library</p><ol><li>Open your terminal or command prompt.</li><li>Navigate to the directory where you want to create your Python virtual environment.</li><li>Run the following command to create a virtual environment named “myenv”:</li></ol><pre>python -m venv myenv</pre><p>4.Once the virtual environment is created, activate it. On Windows, you can activate it by running:</p><pre>myenv\\Scripts\\activate</pre><p>On Unix or MacOS, use:</p><pre>source myenv/bin/activate</pre><p>5.Install the package using pip</p><pre>pip install PyMuPDF</pre><h3>Exploring Document and Page Attributes and Methods</h3><p>After installation,to open the pdf document use the below command:</p><pre>import fitz<br>doc = fitz.open(pdf_file_path)</pre><p>Wait wait… Why do we use <strong>fitz</strong> when we install PyMuPDF</p><p>When you installed PyMuPDF using pip, you installed the library called fitz, which lets you work with PDFs in Python. So, when you import fitz, you&#39;re actually importing PyMuPDF to handle PDF documents.</p><p>Now you can explore various attributes and methods associated with the document and its pages.</p><p>Some of the common operations are :</p><pre># Get the number of pages in the document<br>num_pages = doc.page_count<br><br># Get metadata (e.g., author, title, creation date)<br>metadata = doc.metadata<br><br># Get the table of contents (TOC) as a list of tuples (title, page number)<br>toc = doc.get_toc()<br><br># Load a specific page (e.g., first page)<br>page_num = 0  # Page numbers are zero-based<br>page = doc.load_page(page_num)</pre><p>You have access to a wealth of Document and Page attributes and methods in PyMuPDF. If you want to learn more,do not forget to check out the following links:</p><ul><li><a href="https://pymupdf.readthedocs.io/en/latest/document.html">Document methods</a></li><li><a href="https://pymupdf.readthedocs.io/en/latest/page.html">Page methods</a></li></ul><h3>Text Extraction</h3><p>To extract the text of a single page.</p><pre>import fitz<br># Open the PDF document<br>with fitz.open(&quot;your_document.pdf&quot;) as doc<br> # Load the specific page (e.g., page 0 for the first page)<br> page_number = 0<br> page = doc.load_page(page_number)<br> # Extract text from the page<br> text = page.get_text()<br> # Print or use the extracted text<br> print(text)</pre><p>And if you want to extract text from the entire document and save it to a file:</p><pre>import fitz<br># Open the PDF document<br>with fitz.open(&quot;your_document.pdf&quot;) as doc<br> # Initialize an empty string to store all the text<br> all_text = &quot;&quot;<br> # Loop through each page in the document<br> for page in doc:<br>     # Extract text from the page and append it to the &#39;all_text&#39; string<br>     all_text += page.get_text()<br>v<br> # Add a delimiter indicating the start of a new page<br>    delimiter = f&quot;\\nPage {page_number}\\n{&#39;-&#39; * 20}\\n&quot;<br>    <br> # Write all the text to a file<br> with open(&quot;output.txt&quot;, &quot;w&quot;, encoding=&quot;utf-8&quot;) as file:<br>    file.write(all_text)</pre><h3>Text Conversion Formats</h3><p>Now that we’ve successfully extracted text from our PDF documents, let’s explore how we can convert this text into different formats like HTML, JSON, dictionaries, etc., to facilitate data analysis.</p><h4>Plain text-extraction</h4><pre>text = page.get_text(&quot;text&quot;)</pre><p>By default, this method extracts plain text from the page. It retrieves the text content without any additional formatting or markup.</p><h4>Block Based-Extraction</h4><pre>blocks = page.get_text(&quot;blocks&quot;)</pre><p>It gives output as a list of lines grouped as a block</p><h4>Word Based-Extraction</h4><pre>words = page.get_text(&quot;words&quot;)</pre><p>It gives output as a list of single words with bbox information.</p><h4>HTML, XHTML, and XML Extraction</h4><pre>html_content = page.get_text(&quot;html&quot;)<br>xhtml_content = page.get_text(&quot;xhtml&quot;)<br>xml_content = page.get_text(&quot;xml&quot;)</pre><p>These options enable you to extract text from the PDF page and format it directly into HTML, XHTML, or XML.</p><ul><li><strong>HTML</strong>: The extracted text will be in HTML format, suitable for direct display in a web browser as a webpage.</li><li><strong>XHTML</strong>: Similar to HTML, but XHTML follows stricter XML rules, making it suitable for well-formed documents and compatibility with XML parsers.</li><li><strong>XML</strong>: The extracted text will be in XML format, which can be useful for further processing or integration with other XML-based systems</li></ul><h4>Dictionary and JSON Extraction</h4><pre>dict_content = page.get_text(&quot;dict&quot;)<br>json_content = page.get_text(&quot;json&quot;)</pre><ul><li>These options enable you to extract text from the PDF page and format it directly into Dictionary and JSON</li><li>Both enable easy integration with other Python data structures or serialization for storage and exchange</li></ul><h4>Raw Dictionary and Raw JSON Extraction</h4><pre>raw_dict_content = page.get_text(&quot;rawdict&quot;)<br>raw_json_content = page.get_text(&quot;rawjson&quot;)</pre><ul><li>These options provide access to the raw text content in dictionary or JSON format without any additional processing. This can be useful for advanced text analysis or custom data manipulation.</li></ul><p>When using these extraction methods, it’s important to consider the specific requirements of your project and choose the output format that best suits your needs</p><p><strong>References:</strong></p><ul><li><a href="https://pymupdf.readthedocs.io/en/latest/">PyMuPDF Documentation</a></li></ul><h4>Worth Knowing : IRonPDF, and the One case get_text() can’t cover</h4><p>Good rundown — and the reasoning for landing on PyMuPDF holds up. If the requirement is “extract text <em>and</em> convert it to HTML/JSON/dict,” the get_text(“html”) /<strong><em> </em></strong>get_text(“dict”) family is genuinely hard to beat, and no other library gives you that many output formats from one call.</p><p>Worth adding one alternative and one gap.</p><p><strong>For plain text extraction</strong>, IronPDF for Python is a simpler API if that’s all a project needs:</p><pre>pip install ironpdf</pre><pre>from ironpdf import PdfDocument<br><br>pdf = PdfDocument.FromFile(&quot;your_document.pdf&quot;)<br><br># Whole document in one call — no page loop<br>all_text = pdf.ExtractAllText()<br><br># Or a single page (zero-based, same as load_page)<br>page_text = pdf.ExtractTextFromPage(0)</pre><p>It also opens password-protected PDFs by passing the password as a second argument — handy for the “pile of PDFs” case where one or two are locked. It doesn’t offer PyMuPDF’s <strong><em>blocks/words/xhtml/rawdict</em></strong> variety, though, so if those conversion formats are the point, PyMuPDF stays the better fit.</p><p><strong>The gap worth knowing about</strong> is the one from your opening paragraph — <em>“text inside images was getting copied too.”</em> That’s the flip side of a real limitation: <strong><em>get_text()</em></strong> reads a PDF’s embedded text layer, so on a <strong>scanned</strong> page (an image of text, no text layer) it returns an empty string. No error, just nothing — which in a batch means a file silently contributes zero text and you may not notice.</p><p>Worth guarding for it regardless of library:</p><pre>text = page.get_text()<br>if not text.strip():<br>    text = ocr_fallback(page)   # scanned page — needs OCR</pre><p>For the OCR side,<strong><em> pytesseract</em></strong> is the usual Python route. On .NET, <strong>IronOCR</strong> reads scanned PDFs directly with deskew/denoise preprocessing built in — only relevant if that part of a pipeline ever runs on .NET, since there’s no Python package for it.</p><p><strong>Small things in the code snippets</strong> — worth a look if anyone copy-pastes:</p><ul><li>with fitz.open(“your_document.pdf”) as doc is missing its trailing colon in both examples.</li><li>In the full-document loop there’s a stray v on its own line, and delimiter is built but never appended to all_text — so the page separators don’t make it into output.txt. page_number is also referenced there but only defined in the earlier snippet.</li></ul><h4>Honest note</h4><p>PyMuPDF is <strong>free, open-source, fast, and the right call</strong> for what you described — especially the multi-format conversion. IronPDF is commercial (free trial; the Python API runs on the .NET runtime), so it’s worth a look mainly when the job is straightforward text extraction, or when encrypted PDFs are in the mix.</p><p>The bigger takeaway is the scanned-page guard — that one catches a whole class of silent failures no matter which library does the extracting.</p><p><a href="https://ironpdf.com/python/">IronPDF for Python</a> ·<a href="https://ironpdf.com/python/examples/extract-pdf-text/"> Extract text example</a> ·<a href="https://ironsoftware.com/csharp/ocr/"> IronOCR for .NET</a> ·<a href="https://ironpdf.com/python/"> free trial</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=010cc2c8cab3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>