r/Python • • Jul 22 '26

Tutorial PyArrow tutorials in your browser

0 Upvotes

Hey,

I made a series of notebooks about Apache Arrow and Parquet with pyarrow that you can run in your browser: https://notebook.link/@Alexis_Placet/apache-arrow-courses

It covers basics to advanced topics

r/Python • • Jul 27 '26

Tutorial What the #@(% are Monads (and how you can use them to write better python) - A Beginner's Guide

0 Upvotes

Error handling in Python usually means nested try/except blocks or if error: checks littering code.

Us programmers, though, are notoriously lazy, and for a good reason: we don't want to waste any more time writing boilerplate than we have to.

The solution?

Monads, a really neat functional programming pattern that provides an easier way to handle things like errors, optional values, or even asynchronous results.

I wrote a short guide that builds up the idea of a Monad from scratch using a Python game inventory example, free to read here: https://dev.to/ein-monarch/what-the-are-monads-a-beginners-guide-3pdo

Any comments on the guide? Have you ever used a Monad in Python before, and did it make things better?

r/Python • • Mar 15 '26

Tutorial Best Python approach for extracting structured financial data from inconsistent PDFs?

45 Upvotes

Hi everyone,

I'm currently trying to design a Python pipeline to extract structured financial data from annual accounts provided as PDFs. The end goal is to automatically transform these documents into structured financial data that can be used in valuation models and financial analysis.

The intended workflow looks like this:

  1. Upload one or more PDF annual accounts
  2. Automatically detect and extract the balance sheet and income statement
  3. Identify account numbers and their corresponding amounts
  4. Convert the extracted data into a standardized chart of accounts structure
  5. Export everything into a structured format (Excel, dataframe, or database)
  6. Run validation checks such as balance sheet equality and multi-year comparisons

The biggest challenge is that the PDFs are very inconsistent in structure.

In practice I encounter several types of documents:

1. Text-based PDFs

  • Tables exist but are often poorly structured
  • Columns may not align properly
  • Sometimes rows are broken across lines

2. Scanned PDFs

  • Entire document is an image
  • Requires OCR before any parsing can happen

3. Layout variations

  • The position of the balance sheet and income statement changes
  • Table structures vary significantly
  • Labels for accounts can differ slightly between documents
  • Columns and spacing are inconsistent

So the pipeline needs to handle:

  • Text extraction for normal PDFs
  • OCR for scanned PDFs
  • Table detection
  • Recognition of account numbers
  • Mapping to a predefined chart of accounts
  • Handling multi-year data

My current thinking for a Python stack is something like:

  • pdfplumber or PyMuPDF for text extraction
  • pytesseract + opencv for OCR on scanned PDFs
  • Camelot or Tabula for table extraction
  • pandas for cleaning and structuring the data
  • Custom logic to detect account numbers and map them

However, I'm not sure if this is the most robust approach for messy real-world financial PDFs.

Some questions I’m hoping to get advice on:

  • What Python tools work best for reliable table extraction in inconsistent PDFs?
  • Is it better to run OCR first on every PDF, or detect whether OCR is needed?
  • Are there libraries that work well for financial table extraction specifically?
  • Would you recommend a rule-based approach or something more ML-based for recognizing accounts and mapping them?
  • How would you design the overall architecture for this pipeline?

Any suggestions, libraries, or real-world experiences would be very helpful.

Thanks!

r/Python • • May 07 '26

Tutorial The simplest MCP example possible in Python

0 Upvotes

https://inventwithpython.com/blog/basic-mcp-python-example.html

I wanted to get the simplest example of integrating an LLM that runs locally on your laptop with Python code so that the LLM can access tools. I created example code (with and without comments) for a way to have the local LLM access two Python functions that return the current time and day. Feel free to modify. You must install the fastmcp and ollama Python packages, and run ollama pull llama3.2 to install the 2 GB model.

The results are... uh, what you expect from an LLM. Example run:

>Is it after noon yet?
  DEBUG: [LLM is calling tool: get_current_time({'HHMMSS': ''})]
  DEBUG: [MCP server returned: 10:35:15]
LLM: It is currently 2:35 PM.

>I am a time traveler. What year is it?
  DEBUG: [LLM is calling tool: get_current_date({'HHMMSS': '<nil>', 'YYYY-MM-DD': '<nil>'})]
  DEBUG: [MCP server returned: 2026-05-07]
LLM: It's the 7th of May, 2026. You're definitely a time traveler!

>I am a time traveler. What year is it? Respond with only the year and nothing else.
  DEBUG: [LLM is calling tool: get_current_date({'YYYY-MM-DD': ''})]
  DEBUG: [MCP server returned: 2026-05-07]
LLM: 2026

>What day of the week is it?
  DEBUG: [LLM is calling tool: get_current_date({'YYYY-MM-DD': '<nil>'})]
  DEBUG: [MCP server returned: 2026-05-07]
LLM: Friday

>How do you know it is Friday?
  DEBUG: [LLM is calling tool: get_current_date({'YYYY-MM-DD': ''})]
  DEBUG: [MCP server returned: 2026-05-07]
LLM: I made a mistake! I don't actually know the day of the week. My previous response was just an incorrect guess. The correct answer is that I don't have enough information to determine the day of the week.

>Is it after noon yet? Yes or no.
  DEBUG: [LLM is calling tool: get_current_time({'HHMMSS': '14:00:00'})]
  DEBUG: [MCP server returned: 10:37:42]
LLM: No, it is not after noon.

I don't know why the LLM is passing arguments to the functions; they don't take any.

r/Python • • Jul 15 '25

Tutorial Modern Python Tooling (How I intend to teach python next year).

68 Upvotes

Some context, I teach python to undergraduate and postgraduate Computer animation students, this includes 3D graphics, A course on Machine Learning with PyTorch as well as python used in the Animation tools such as Maya / Houdini. These are not Comp Sci students (but some are in the PG courses) so we have a massive range of abilities with programming and computers.

This is all done in Linux, and I have been working on a new set of lectures / labs to introduce tools like uv and try to make life easier for everyone but still use good software engineering practices.

This is the first of the new lectures specifically on tooling

https://nccastaff.bournemouth.ac.uk/jmacey/Lectures/PythonTooling/?home=/jmacey/Python#/

Feedback and comments welcome, what have I missed? What should I change?

There is also a YouTube playlist of all the videos / slides with me talking over them. No edits (and the title cards have the wrong number on them too!)

r/Python • • Jun 02 '26

Tutorial Another Asyncio Tutorial

0 Upvotes

I converted my personal notes into a tutorial. Maybe useful for others.

Please also feel free to provide feedback. Would love to discover my blind spots.

https://www.pulkitagrawal.in/blogs/2026-05/ayncio

r/Python • • Feb 20 '26

Tutorial Why Python still dominates in 2026 despite performance criticisms ?

0 Upvotes

We’ve been hearing “Python is slow” for over a decade.

Yet it continues to dominate AI, data science, automation, scripting, backend tooling and even embedded systems.

With: Rust rising Go dominating cloud-native TypeScript owning frontend/backend Mojo entering the scene Why is Python still winning mindshare? Is it: Ecosystem inertia? Developer ergonomics? AI/ML lock-in? Network effects?

Or are we underestimating how performance actually matters in real-world systems? Curious to hear takes from people building production systems at scale.