PDFs in Python and Projects on the Raspberry Pi | Real Python Podcast #13

Real Python · Beginner ·📰 AI News & Updates ·6y ago

Key Takeaways

The video discusses working with PDF files in Python, including extracting text, merging and concatenating files, and creating PDFs from scratch, as well as building hardware projects using a Raspberry Pi.

Full Transcript

welcome to the real Python podcast this is episode 13 if you wanted to work with PDFs in Python maybe you want to extract text merge and concatenate files or even create PDFs from scratch are you interested in building hardware projects using a Raspberry Pi this week on the show we have David Amos from the real Python team to discuss his recent article on working with PDFs David also brings a few other articles from the wider Python community for us to discuss David searches for the latest Python news links and articles to produce pi coders weekly with Dan Bader my coders weekly is a free email newsletter for those interested in Python development and along with david's article on pdfs we discussed another recent real Python article on building physical projects with the Raspberry Pi and we also discuss articles from the community about the peps of Python 39 why you should stop using date/time dot now I thought dependency tools in several ways to pass code to Python from the terminal alright let's get started [Music] my name is Christopher Bailey your host the real Python podcast is a weekly conversation about using Python in the real world interviews with experts in the community and discussions about the topics articles and courses found at real Python comm after the podcast join us and learn real world Python skills with a community of experts at real Python comm hey David welcome to the podcast hey thanks for having me yeah so we're doing something slightly different this week I brought David on board it's a bit of an experiment and we're gonna try this out we're also gonna continue to ask the weekly questions at the end so like I said we're just gonna alternate between these topics and kind of go into depth and of course all this stuff's gonna be heavily connected through lots of show notes and links please check that stuff out either in your podcast player or again at real Python comm slash podcast so David what's your first topic there a first one I've got is an article written by Brett cannon called the many ways to pass code to Python from the terminal Brett cannon for those that don't know who he is he's a works for Microsoft and he's the manager for the distributed development team of the Python extension for Visual Studio code so if you use Python and vs code he's one of the managers for that project he's also a member of the Python steering council cool so he's a pretty important guy in the in the Python world and he put together this article called the many ways to pass code to Python from the terminal so most people are probably familiar with running a dot py file by just typing Python and then the path to that file that's a pretty common way of running a Python program sure but there's lots of other ways to pass code it's a Python from the terminal some of which I had never even heard of before cool so he's got six different ones in in this article and I'll just kind of go through and kind of summarize each of them real quick the first one he mentions is piping from standard in which you can if you have for example you can echo something on the UNIX terminal pipe that into a Python command and it'll execute whatever you echo you can also redirect a file into Python using a little less than symbol or the left carat whatever you prefer to to call that and so these are the kind of your standard UNIX e type ways of shuffling data around on the terminal and he says here you know there's nothing really surprising there thanks to pythons UNIX heritage so it's probably not something you'd use very often it's just kind of a corollary of of Python coming from from a UNIX background yeah another one and this one is actually pretty useful is running Python with the - C flag which allows you to pass a string into Python and have it just run that that string so if you do Python - C and then in quotes print high it'll run that print function and print high on the on the terminal so you can do this if you need to check just a couple of lines of code without having to actually launch the repple okay so that's kind of a neat way to do it so you could do like a test of like a import or something like that to make sure that it's available or something something like that or just if you run a quick couple of lines of code you want to see how it works or what the output is okay then there's using B - M flag to run a package and I think some people this is going to be a little bit less familiar than using Python with like a file path but I think it's it's relatively common these days if a lot of people that use the bian package from the standard library run that as a package that you do the Python - and BM to create your virtual environment so this is how if you have a package that specifies add under main dot p py file then it'll it'll run that package a couple of them that I thought was kind of surprising and I'd never heard of before is you can actually run a directory which I guess in retrospect it's sort of like running a package kind of yeah but I'd never really thought of it that way so if you just have a directory that has add under main DEP you I can run that directory as if it were a package but the one that was really surprising to me is executing a zip file this is something I had no idea that you could do and had never even thought about it huh but it's if you have a zip file that contains a dunder main dot py then you can point python at that and I guess it will decompress that and run whatever is in there nice that's very cool yeah I was familiar like two of us yeah that's really cool it's a whole bunch of additional tools for running your code so my first one is called the peps of Python 39 and it's by Jake edge at lwn net which I guess maybe it used to stand for Linux weekly news but it's not that sites not purely focused on Linux anymore yeah Python 39 the beta release is already come out I think a couple weeks ago now and so it's sort of going into what's going on with the peps that are in there and if you're not familiar with Epps's or python enhancement proposals these are the ones that we're accepted as part of python 3 9 so you can check them out as part of the beta the first one that they go into in the article is pep 6 1 6 or 6 16 and it's about string methods that can remove prefixes and suffixes you might think of like the existing methods that can allow you to remove sort of you know strip things from the beginning our strip and L strip and the problem with them is that they remove all the characters that you include in there they're not specifically like you know what you'd set up is like a prefix or a suffix at the end of a string and so this is being much more specific and having done a real deep dive on string methods I could see how these could be added and could be useful in certain circumstances yeah for sure yeah get something a little more specific and cause maybe a little less confusion or errors the next one is actually right next in order pep six one seven is about a new PEG parser PE G parser for C Python and it was proposed by Guido van Rossum himself and a couple others Python originally developed by Guido 30 odd years ago is currently using an LL 1 parser and parses things from left to right and left most derivation it kind of just goes through grab each individual token and kind of combine them together and the peg parser is parsing expression grammar and so one of the reasons for I guess he worked with the owl originally had to do with I guess memory and the limits of computers and memory if you even go back 20 years ago is pretty drastic compared today and computers have so much more of that memory now even Raspberry Pi something I'll talk about later come with you know incredible amounts of memory and we're not quite needing to do the parsing quite the same way but anyway it kind of goes into that and and guido has a separate series of articles on medium about peg parsers in case you're interested in learning a little more about what the proposal is and I think the proposal actually talks about it having not only the ll 1 but the peg parser kind of both running in 39 which it may then think the goal is to have it replaced in 310 anyway so his whole idea is gonna allow for a lot more flexibility in the evolution of the language and how the language is parsed so getting some deep computer science there yeah from what I understand about it there's there's some parts of the language that requires some real kind of hacky type things that they had to do to get them to parse correctly or to be understood correctly and that this is gonna alleviate some of that and allow them to write I guess some cleaner code around those those sections and just handle it more naturally which i think is always a good a good thing - yeah absolutely and it looks like there's possibly a little bit of a performance boost from it like around the order of like 10% that's good so the next one is uh pep 6-1 5 which is support for the ia and a time zone database to be built into the standard library and IA na the internet assigned numbers authority standard that's out there before that you would have to kind of usually import additional time zone packages to help with that that'll be kind of nice to have that built in the article touches on at 593 which is a kind of goes a little deeper into type hints with flexible function and variable annotations and the last one I want to touch on is just pepp 602 which I spoke briefly about with Lucas Longo when he was on episode 7 he's the current release manager for Python 38 and 39 and he mentioned how you know one of the big changes was for them to switch over to this yearly release standard this annual release cycle for Python compared to an 18 month cycle and he was talking that he was thinking back in episode 7 that he was going to be the manners for Python 310 and actually they have found a different release manager his name is Pablo Galindo Salgado he's gonna be the next release manager which once the first beta comes out that's when they start actually start looking at 310 and so we start working on that soon yeah what's your next article well actually I want to clarify something real quick I just realized about the pec parser yeah go ahead so it's not that there's necessarily a 10% boost in performance it's that the performance is within ten percent of the existing parser so it could be okay it's like a plus or minus there so sure okay so yeah which shouldn't be a big hit one way or the other hopefully exactly yeah good okay thanks for clarifying yeah I just happened to notice that as I was reading through this the article well the next thing I've got is perhaps a little biased but it's it's one of my own that we just released on real Python comm weeks ago now or I don't know the exact the exact date but it's it's creating and modifying PDF files in Python it's obviously about PDF files it's a thorough introduction to working with PDFs in Python but it's not an exhaustive reference so it's really geared towards newcomers to the Python language and it's it's people who want to find practical uses for for Python in the real world and some of the things that it covers are how to read text from a PDF how to extract text from a PDF into a txt file how to concatenate files which is where you take all the pages from one PDF and then all the pages from a second PDF and just sort of tack those pages on from the second one in order place and then also how to merge files so if you have two PDFs and you want to maybe insert the pages from one PDF in the middle of another one that's what would be merging those two files we also talked about how to crop pages rotate pages encrypt and decrypt PDF files with passwords and also get into a bit of creating PDF files using the report lab package oh nice which is a popular third party package for for creating PDFs programmatically with with Python yeah I've been interested in that report lab tool I was working on a project for this environmental science company and we were constantly trying to make tools for them that were kind of paperless if you will yeah and so I was using what I would argue is still one of the most clunky things that Adobe's ever created which is Adobe Acrobat in some ways I think creating PDFs programmatically can be more consistent and more more straightforward so I'm intrigued to read more about it there yeah so report labs are very powerful package you can do a lot with it because of its power it's actually they can be a kind of complex so this is a very gentle introduction to getting started with that but it doesn't really touch on a lot of the more powerful features in report labs so it's just a kind of a whet your appetite a little bit kind of show you explain some of the basics of the different things that are needed there to create PDFs and then this new set you up to take a deep dive yeah later on reporte has great documentation they've got a whole guide that you can read that I think it's it's over a hundred pages awesome they put together some tutorials and walkthroughs and everything so yeah good stuff but one of the things that I thought was interesting while I was researching and writing this this article was the history of sort of these PDF packages in Python ok from manipulating PDFs the package that we use in the article is called PI PDF - yeah so there must have been a first version at some point I kind of looked at you know ok what's what's the story here and well there was a PI PDF package that was created in 2005 actually I've got it as about 15 years ago yeah by someone oh and I'm gonna try to pronounce his name Matthau fen yak in 2005 launched this pi PDF is a PDF toolkit focused on document manipulation introspection page cropping encryption/decryption so kind of the basic things you do with with a PDF in 2011 there was a company called phase it that sponsored a new Fork of Pi PDF called pipe PDF - which is what we're using in the in the article ok and it's the description here says the initial impetus was to handle a wider range of input PDF instances phase its commercial work often counters PDF instances in the wild that it needs to manage mostly concatenate and paginate but to deviate so much from PDF standards that PI PDF couldn't read them so PI PDF to is meant to better handle the PDFs in the wild that weren't obeying all the standards to a to a T so it's a little bit more flexible good yeah yeah there's lots of things that generate PDFs not exactly yeah well as a research deeper I figured I found out that there's a PI PD F 3 and a PI PD F 4 okay and I looked into you know what's what's going on here should we be using some of these newer packages and as far as I can tell the author of Pi PDF to created a new fork called PI PD F 3 and labeled it as a continuation of Pi PDF 2 and then abandoned it sometime in like 2017 2016 2017 ok and I'm not sure what the difference is there and then just into 2018 so a couple years ago someone made a fork called PI PD F 4 and there's no difference at all in the API or anything in PI PD F 2 they just mentioned that they were it was they were creating this new fork because of a new business model that they were trying and I have no idea what that means ok and also it seems to the last commit was over a year ago so I'm not sure what these regressed back to 2 so PI PD F 2 seems to kind of be the standard package and it's all Python 3 at least I found 3 at least it is compatible with Python 3.8 as far as the code and the article has been tested on 3.6 3.7 3.8 ok cool so the last thing I wanted to mention about the PDF well there's two things I wanted to mention first of all is that this the article is actually a preview of a chapter of the Python basics a practical introduction to Python 3 book that I have been working on with dan for about two years now yeah that's a bit an ongoing project and we'll talk more about that I think later so if you interested in in in that book or heard about it or even heaven go see get a a taste of what's in there by looking at this this article yeah but I also wanted to mention that you know PI PDF to report lab these aren't the only packages for working with PDFs and so I've got a little list here of some other things that as I was researching I came across and thought were some some interesting entries into that genre of Python packages cool there's another popular one popular one called PDF RW which is for reading and writing PDF files it's a bit lower level than PI PDF to so it's kind of gives you more control over how things are read and written but it's also doesn't have quite as simple of an API that PI pf2 has there's one called PDF miner which is another popular one for extracting data from the PDF yeah and I just saw that as of 2020 it's now no longer being actively maintained and there's a new fork called PDF miner 6 si X which is the active repository now ok there's one called Camelot which is a relatively recent package that's strictly for extracting tables from PDFs which is a very common operation and there's another brand-new one that we featured in pi coders issue number 421 called pi PDF parser and it also seems to be focused on text and tables so there's lots of lots of packages out there for for working with with PDFs that some are a bit more low-level and some are just kind of more focused on specific tasks whereas pi pf2 is a much more general solution for for lots of things it's interesting because I think it would kind of go along with a conversation I had with Kimberly vessel about web scraping and how you know a lot of the web isn't HTML a lot of things maybe files that you might be trying to grab and so yeah the most common way that well I think the most common way that things are passed around on the internet as documents or PDFs and so if you're wanting to do data science kind of stuff and collect data out of your PDFs these tools on top of something like selenium that could help you or scrapey that could help you download those individual documents and then this could go inside the documents and pulls information out absolutely so that's very cool yeah [Music] this would go on a shine a spotlight on another real Python video course it's called cool new features in Python 3.8 and it's by me I created this course based on the great article written by previous guest Guerin yella it's a good way to wrap your head around the new features found in Python 3/8 and in the video course you'll learn about the Wohlers operator and how using assignment expressions can simplify some code constructs you also learn about enforcing positional only arguments in your own functions specifying more precise type ins using f strings for simpler debugging and about some of the new warnings about dangerous syntax I think it's a worthy investment of your time to understand what the most recent release of Python provides before moving on to the next version that's coming this fall and like most of the video courses on real Python the course is broken into easily consumable sections and you get code examples for the techniques shown you can find a link in the show notes or you can find it using the newly enhanced search tool on real Python comm [Music] okay so my next one is an overview of Python dependency management tools and it's by Mario Costa Lac and that's at model predict comm and it kind of goes into talking about Python package management and dependency management and the whole ecosystem that's grown inside of Python which is pretty large of all these different sorts of tools that are out there and they're all in kind of different sort of States and so it's a really good overview of all these different tools that are out there it starts with pip obviously which most Python users probably have used pip is the package installer for Python and pip when you type in pip install one of the name the packages it talks to pi pi which is the Python package index and you know grabs that information and installs it and pip has a set of tools in fact we just released a course on this there's a existing article on using pip a real Python but there's a there's a course that I'll mention a little bit more later it goes into using pip and all the kind of other kind of tools and techniques that people may not be aware of what you can do with it and then it kind of goes into then which you mentioned earlier ve and V which is something I use it for virtual environments it's built into Python I think it came along in either Python 35 or 36 yeah I use this for you know creating all my courses because I don't want to be changing my existing environment and my Python install to experiment on new things like if I'm going to do you know a course on PDFs or something like that and I'm gonna try a lots of different packages it's nice to be able to have this virtual environment something I can kind of create and work inside of and and so forth so it kind of goes into that and then it talks about pip tools and pyenv I am yeah and then I'm not going to spend too much time talking about I mean it goes into all of those it spends quite a while talking about Kondo which is really popular in the data science world distributed by anacondas and there's also the lighter version called mini Conda what's interesting about that whole environment if you will it has its own virtual environment manager inside of Conda and its own package manager you can use pip with it but it's really if you start going into that environment makes a lot more sense to kind of do all your management through Conda inside of anaconda in that whole world there and then it Khan dives into two that are sort of similar pip EV and poetry which basically they kind of manage the workflow the you know manage the environments that you're setting up the help you with installing the Python packages and kind of making your environment reproducible and then they can also get into this really nice advanced topic of like packaging and publishing your own Python packages so if you were thinking about submitting something to IPI those are the types of tools that you might need for that and they can help you with getting things going on that and then the last is to just talk a little bit the odd duck and the whole bunch of things is they talk about docker which is another way to manage environments and yeah we talked a lot about that and episode 8 of the podcast talking about using that for data science and other uses but Dockers are a great tool just again sort of isolate your setup and also hopefully make it reproducible and deployable out there in the cloud and things like that yeah docker is is a really great tool yeah I've been using it more and more for the past several years and felt like a bit of a steep learning curve yeah and I think there's a lot of misinformation out there or perhaps bad information there's some really good best practices that if you follow kind of make it easy to get more reproducible builds and have it be more portable and yeah distributable but yeah it's a really it's a fantastic tool I wanted to mention I really like pip tools ok cool and have started you started using that more more and more recently and one of the things that I like about it is you know I've been using pip for a long time whenever I work with virtual environments I just always use the VM package that's now on the the standard library so things like you know PI N and Pippin and poetry I've I honestly haven't played with poetry too much I looked at Pippin for a little while thought it was it was neat you know I already had my own workflows kind of built out and thought thought through and liked the way that I and was doing things and it seemed to be it was obscuring a lot of that stuff from me and it was difficult to sort of understand like exactly how is it managing be the virtual environment and is it the way that I wanted to be working it right so one thing that I really like about Pip and assumed poetry does this too I haven't checked but is that instead of having to specify all of your dependencies you can just specify like well I want to install jingo well Django has a whole bunch of other dependencies but you know normally in a kind of the standard workflows you would you know install Django Pips gonna collect all of its dependencies and then you would run something like pick freeze and dump it into a requirements a txt file and you get this big requirements that txt file that has all of the dependencies in there and it kind of becomes a nightmare to maintain that that text file and understand like well when I update one tool do I do any updating other one are not updated or it just gets kind of kind of confusing and so one of the things that I liked about pip pip is that you can just sort of manage this you know this this pip file that's got your main dependencies in it and then the lock filed it file dot lock will have the dependency tree resolved for you but it's sort of handled in the background so pip tools sort of does something similar and allows you to just specify the main dependencies that you want okay and then it can generate a requirement txt file for you but you you put your dependencies that you're like your main dependencies that you're really interested in in like a requirements dot in file dot I n okay and you just have to maintain those like you know you want Django and you want I don't know like maybe a markdown extension or something for it and you don't have to worry about the other all the the other dependencies but it doesn't manage the virtual environment for you so it really sits nicely on top if you have a pre-existing virtual environment workflow that you use it really fits in nicely with that so I thought that was a really cool tool nice yeah kind of a nice mid mid way option between hip and like poetry and poetry yeah he has a nice chart at the bottom which kind of goes into you exactly what you're talking about kind of comparing the solutions and what to do it installs Python packages installing non Python packages managing versions and managing your virtual environment or the whole idea of environment reproducibility and right yeah it's a it's a good it's a good guy to you know to kind of give you an idea at the landscape so what's what do you got next my next article is called stop using date time dot now and it's a kind of a shocking title um why would you stop using date I've got now how else you gonna get the current time right well the subtitle is practical dependency injection in Python so yeah they seem kind of different yeah how are those two things related that seems kinda so this was a really really cool article that that I found that it's actually comes from one of the real pythons contributors hacky Benita who's written several fantastic articles about Django for real Python he talks about how you would approach testing a function that uses day time now that's called in the function and you want to make sure that that function is working appropriately so how do you test that you can't predict when you're gonna run the test and what time day time but now should be returning so he talks about some third-party tools that you can use to to solve this for you there's a there's a couple freeze gun and Lib fake time which I've used freeze gun before it allows you to add a decorator to a test case like if you're using PI test by test okay test case that allows you to set the time that's going to be returned by date/time so if you want to it allows you to freeze it to say make sure it always returns June 4th 2020 and then you just know that that's what's going to be returned and you can treat the test you can you can write your test with that knowledge however the downside is that you need these third-party libraries in order to do that and sometimes you don't have the luxury of being able to depend on those it's it's generally if for like a legacy system this is really really good to have these third-party dependency but if you're writing something from scratch and you want to keep your dependency tree as small as possible then you may not want to have to rely these these packages so how do you approach this and the idea comes down to something called dependency injection so he gives an example of where you're gonna write a function called tomorrow and it should return the date of tomorrow so kind of the naive approach would be okay I'm gonna define my function that's gonna return the date time today which gives you today's date and plus one day which using the date time time Delta function if you're if you're familiar with that but you just add one to the date returned by today well then how do you go in and test that that that is actually working it's kind of impenetrable you can't really test it so there's a couple ways to do it would one would be using something like a mock or you could monkey patch the day time duck today function but that gets a little messy and may not be a good solution for you so the solution that Hecky recommends or at least urges you to think about it may not may not be the right choice for what you're doing but something to think about is to remove the dependency of the function on that date time today function and turn it into a parameter so you would pass something to that function that is supposed to return today's date and that's what gets used in the function hopefully that that makes sense yeah right so you'd have tomorrow and it has a parameter in his example it's as of and so you pass something to that as of parameter that is supposed to be the date for which tomorrow will be calculated so that kind of generalizes the function now you could say well what is tomorrow as of you know last week yeah but one week from today but it gives you the date after whatever date you pass to it so now you're able to test that it's actually working because you can you can inject the value that you that you want and make sure that you get the return value that you that you expect from it so it gives you more control and he talks about the different types of dependency injection so what I just described was actually injecting a value but you could also inject a function so rather than just injecting B the value that you want to calculate tomorrow from you could actually inject the function that is that computes the date of today so you have control over what function is being used inside of your function so that's just a it's a really nice overview of what dependency injection is how it works why it is a desirable thing to use in in programming and how it can help you make code that's easier to maintain easier to test yeah and it's more practical it's giving you that kind of real world example of dealing with dates and times and absolutely yeah well yeah there's a whole section called dependency injection in practice he talks about different scenarios so one is IP lookup so you want to try to guess where visitors to a Django site are coming from and and then want to test that whatever system you come up with actually works and how dependency injection can help you with that help you solve that problem yeah cool my last one is actually another real Python article nice and something I'm very excited about because now I have two of them it's build physical projects with Python on the Raspberry Pi and I have a Raspberry Pi 3 and I have a Raspberry Pi 4 I just recently got and yeah this came out on June 1st you know then the tutorial goes really into detail on setting up your Raspberry Pi which i think is excellent because the resources for that are very scattered on the web and this gives a really good compilation of like you know starting from scratch like here's a Raspberry Pi and we're adding you know memory card formatting it putting on the operating systems the different flavors of that kind of stuff it so it's really good on that kind of background stuff which I thought was awesome and then it goes into the built-in mu editor for working inside of Python which is a nice I want to call it an ID but it's you know basic Python editor text editor that's in there then he includes some details which I think are great it includes details about how to connect a via SSH to your Raspberry Pi and which would allow you to potentially connect and run this thing headless without a monitor and all that sort of stuff yeah and so I decided to go ahead and do that and played around with it myself and so I you know created the SSH keys I got to try out an area vs code I have never used which is the ability to ashh in and remotely connect to this Raspberry Pi Villa's code which was really great yeah it talks a little bit about you know how you could use other text editors in the terminal they were like vim and I'm at a point in my career where I'm not super excited about learning them it's just there's so many key commands and things to memorize at this point that you know I could imagine doing it but it's just like it would be literally like a little project in order to get up to speed and I think the idea of remotely connecting by SSH seems like way more interesting to me and keeps me creating so yeah the ability to connect with vs code is is really really cool I tried that out as well and they've got some really cool tools built in there now that yeah that make it just really easy to to connect and ink it up and running slick I will say though that I mean it depends on on what your what your role is at your at your job but sure absolutely you know the in vim are can be very essential if you spend your day yeah you know having to SSH do these things and that's literally all you have available yeah I know I I know I need to I need to learn them and you know it's a matter of doing it but yeah this is kind of nice yeah for sure I know real Python has a bunch of articles on it too so I'll have to take the time to dive into deeper do vim that's my dark secret that I don't know it as the article talked about it gets really into the hardware side of it and I think a lot of people may not realize like you know how much connections are built into one of these things there's yeah huge connection boss of pins that are on the side of that and they're all this sort of general purpose input output stuff along with you know grounds and voltage stuff is very similar to like I did a course on the Arduino as a lot of the similar kind of digital functionality there but you know you start with a button and making a script that responds to it and of course connecting LEDs it just really common kind of basic stuff then you move into buzzers and then sort of advanced thing that you kind of create at the end is building up to a project where you have a motion sensing alarm yeah and along with that it has a log which i think is really kind of neat where can actually create this whole CSV file where it's indicates when the motion sensor went off times and all that kind of stuff and it's kind of neat little system and you know out of all that stuff I actually went on Amazon to see like what a passive infrared motion sensor costumes like a pack of five was like I don't n dollars or something yeah it was pretty reasonable so I haven't bought one yet but now I'm totally intrigued to do that myself so yeah yeah it's a it's a neat article yeah very very cool and one of the things I love about this article is the illustrations that he's got for thee how to connect things to oh yeah the Raspberry Pi so he's he's put a lot of well I think he used a tool but I'm sure it still requires some effort to aim you got to think about how all this this gets connected but he does a fantastic job of explaining in words how the wiring should be set up and then also providing a really like easy to look at an Ambu ttle diagram of the breadboard next to the all the GPIO pins on the Raspberry Pi and how it all needs to be wired up and it's all color-coded and I think he did a really really great job with that yeah good job Jason I also really like that it's got it kind of works its way up to this final project so if you don't happen to have all the components right for that final project you can still build there's like four other projects that you might be able to build if you just have a button there's one that it just uses the button and if all you have is an LED then there's one that just uses the LED so I thought that was right it was really neat yeah yeah and so that kinda helps you kind of think of offshoots of your own kind of projects that you could kind of build from there and there's actually a nice list of other potential resources for projects that you could build too which i think is great yeah so have you heard that they're gonna release a Raspberry Pi for that has 8 gigabytes of memory it took me a while to get my 4 gigabyte one it was like that kind of like sold out for months kind of thing last summer yeah and finally sometime in the fall it was like yeah I could get one I mean that thing's amazing that fact you can attach two 4k monitors to this tiny little thing yeah is shocking so I've done the I mean he talks about a little bit you know other things you could do with a Raspberry Pi but the idea that you can you know do the game emulation and even just as a neat Python device or you know a device that you can sort of set up like my wife wants me to do this crazy Christmas light project so I'm feeling like this may be a nicer tool for me to set up because then I can kind of like SSH into it and monitor it and to check out how things are going and we'll see how my Christmas project goes nice yeah cool so I wanted to end the episode with our typical questions but this time I'll get a chance to chime in and know my weekly questions are what are you excited about in the world of Python and again that could be a packaged hardware editor event things that are going on inside the Python worlds so you got this week yes is something I'm really excited about is the Python basics book which I mentioned we will be releasing that at the end of June or the very very beginning of of July we'll have the final electronic version done oh cool with professional edit everything kind of buttoned up and finally put all together that's been a heck of a wild ride getting a couple years you said a couple a couple of years my house flooded twice during the process of writing writing the book so it's it's just been a lot of effort and but it's been a phenomenal process working on that with with Dan and Joanna and the rest of the editorial team so I'm super excited to finally get that done and finalized and out into the world and well there'll be some more news released about that as we get closer to the to the date but yeah I'm just thrilled to finally yeah see that coming to light well I think of that you know that's it's kind of going beyond the basics you kind of get into a lot more of this applicable stuff that you've done at least two of them I could think of now as the PDF article that you is you know partially from the book and then you have another one about gooeys yes in doing stuff and tkinter which is another article people can check out on unreal Python if they want to get an idea of the thoroughness and the things that you know go beyond basics actually doing things with the basics which is cool yeah that's that's true it's called Python basics and it starts with no assumption that you've ever programmed before so it starts from sure the very basics and walks you through getting an environment set up and getting started programming with Python talks about the language and everything and you go through that whole I think the whole first half of the book is devoted to teaching you the Python language the second half of the book is actual practical applications so we talked about working with PDFs we talked about scripting the web working with databases working with files building a GUI as you mentioned we do briefly cover like plotting numpy we don't talk about pandas or that too much but we took map plot live and numpy it just as kind of a short introduction to that yeah that world yeah there's a lot of real world applications there but so the idea is when you're done with the book I mean you've you've learned Python but you also have an idea of how you actually use Python and have built yeah a few different projects to kind of get you started and dive in a whole bunch more real Python stuff from there oh oh yeah tons of stuff yeah that we have a whole resource page that you could access to when you purchase the book that kind of fans out into all the different content that we have on unreal Python to kind of let you explore further and gain more skills and and practice what you've learned cool so mine is I'm super excited about w.x Python which another GUI yeah I'm creating a course for it I'm kind of about halfway done with it so it'll be you know coming up coming the months and so but I finally got a nice project to build with it and it's involving musical instruments that I've had for a long time but you know I used to live in Hawaii and I never really kind of set up my recording studio and did much music stuff there it just kind of dabbled and so I'm excited to kind of get back into that so I unearthed like this old rollin JV 1010 sound mile I have which has thousands of sounds in it and then I started playing with this program called Ableton Live in it unfortunately isn't have a great tool for choosing the banks of sounds and sending out what are called program changes and I was like oh this is a perfect project so I've started on it to kind of mess around with wx-- Python and give this visual interface and connect to this database of sounds and then be able to you know click on these sound names as opposed to like having to go look in a book and type in numbers and nice yeah enter and all that stuff so it'll be it'll be nice a kind of little side tool mostly just for me but you know I'm just excited to kind of get another real-world use for WX python there yeah that's super cool so the next question is hey what do you wanna learn next in Python you know I have never really had an opportunity to learn really in-depth all the async i/o stuff okay yeah I've never had the opportunity to really do a deep dive into async i/o and and learn more about that I've had the opportunity to actually do the technical review on a couple of our async i/o articles and and of course you have to do a bunch of research fact-checking on that kind of stuff and yeah and you get a taste on it and so I'm familiar with with some of the basics but it still you know seems like a bit of a mystery to me so most of the work that I've done professionally is involved a lot of cpu-bound type stuff where we're doing a lot of number crunching and and everything so all the i/o bound stuff is I've used requests yeah sure but never had a need for the power of something like async i/o so yeah something I definitely want to learn yeah cool I'm kind of built on top of my other project there when I talk to Lucas log about his async i/o talk at PyCon he was using a Python package in his example project that you know I had up on github this package called Python - RT MIDI and I guess RT MIDI is a C++ library and Christopher aren't created a library to implement that in scythe on and it's really nice it kind of breaks the MIDI commands and that's our stuff down pretty pretty simply and I already kind of played around with just doing fundamental stuff sending notes and sending these program changes with it just like really simple scripts so I'm excited to you know tie that into my WX Python thing and build on top of that with a with that and kind of going back to yours um Lucas has this really great series on async IO not only is talking Icahn but in with his edge DB yeah with this company at edge DB he's created a whole series of video tutorials on async ion which are really good so nice I'll link to that stuff again so I gotta check those out yeah totally well hey thanks for coming on the show and sharing all these articles with me yeah thanks thanks for having me this is a lot of fun all right talk to you soon yep talk to you later I want to thank David Amos coming on the show this week and bring it along all those great articles and I want to thank you for listening to the real Python podcast make sure you subscribe to the podcast in your favorite player and if you like the show leave us a 5-star rating and a review you can find show notes with links to all the topics we spoke about inside your podcast player or at real Python comm slash podcast and while you're there you can leave us a question or a topic idea I've been your host Christopher Bailey and look forward to talking to you soon you

Original Description

Have you wanted to work with PDF files in Python? Maybe you want to extract text, merge and concatenate files, or even create PDFs from scratch. Are you interested in building hardware projects using a Raspberry Pi? This week on the show we have David Amos from the Real Python team to discuss his recent article on working with PDFs. David also brings a few other articles from the wider Python community for us to discuss. David searches for the latest Python news, links, and articles to produce PyCoder's Weekly with Dan Bader. PyCoder's Weekly is a free email newsletter for those interested in Python development. Along with David's article on PDFs, we discuss another recent Real Python article about building physical projects with the Raspberry Pi. We also discuss articles from the community about: the PEPs of Python 3.9, why you should stop using `datetime.now`, Python dependency tools, and several ways to pass code to Python from the terminal. Topics: - 00:00:00 -- Introduction - 00:02:06 -- Ways to Pass Code to Python From the Terminal - 00:05:54 -- The PEPs of Python 3.9 - 00:10:54 -- Creating and Modifying PDF Files in Python - 00:18:51 -- Video Course Spotlight - 00:19:56 -- An Overview of Python Dependency Tools - 00:26:55 -- Stop Using `datetime.now` - 00:31:44 -- Build Physical Projects With Python on the Raspberry Pi - 00:38:18 -- What are you excited about in the world of Python? - 00:42:29 -- What do you want to learn next in Python? - 00:44:31 -- Thanks and Good Bye 👉Links from the show: https://realpython.com/podcasts/rpp/13/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Real Python · Real Python · 0 of 60

← Previous Next →
1 A better Python REPL – bpython vs python interpreter
A better Python REPL – bpython vs python interpreter
Real Python
2 Introducing large-type.com – A Utility Website
Introducing large-type.com – A Utility Website
Real Python
3 Reading Hacker News Without Wasting Tons of Time
Reading Hacker News Without Wasting Tons of Time
Real Python
4 Forward References and Python 3 Type Hints
Forward References and Python 3 Type Hints
Real Python
5 Using Sublime Text as your Git Editor
Using Sublime Text as your Git Editor
Real Python
6 Python Code Linting and Auto-Complete for Sublime Text
Python Code Linting and Auto-Complete for Sublime Text
Real Python
7 Make your Python Code More Readable with Custom Exceptions
Make your Python Code More Readable with Custom Exceptions
Real Python
8 Write Better Tests with Sublime Text's Split Layout Feature
Write Better Tests with Sublime Text's Split Layout Feature
Real Python
9 How to Use Sublime Text from the Command Line
How to Use Sublime Text from the Command Line
Real Python
10 Rename Variables with Multiple Selection in Sublime Text
Rename Variables with Multiple Selection in Sublime Text
Real Python
11 Sublime Text Settings for Writing PEP 8 Python
Sublime Text Settings for Writing PEP 8 Python
Real Python
12 Write Cleaner Python with Sublime Text's Indent Guides
Write Cleaner Python with Sublime Text's Indent Guides
Real Python
13 Sublime Text Whitespace Settings for Python Development
Sublime Text Whitespace Settings for Python Development
Real Python
14 Function Argument Unpacking in Python
Function Argument Unpacking in Python
Real Python
15 Python Code Review: Debugging and Refactoring "Conway's Game of Life" +  Automated Tests
Python Code Review: Debugging and Refactoring "Conway's Game of Life" + Automated Tests
Real Python
16 Using "get()" to Return a Default Value from a Python Dict
Using "get()" to Return a Default Value from a Python Dict
Real Python
17 A Python Shorthand for Swapping Two Variables
A Python Shorthand for Swapping Two Variables
Real Python
18 Python Code Review: Refactoring a Web Scraper, PEP 8 Style Guide Compliance, requirements.txt
Python Code Review: Refactoring a Web Scraper, PEP 8 Style Guide Compliance, requirements.txt
Real Python
19 Click & Jump to Test Failures from the Command Line (iTerm2)
Click & Jump to Test Failures from the Command Line (iTerm2)
Real Python
20 Setting up Sublime Text for Python Developers
Setting up Sublime Text for Python Developers
Real Python
21 Sublime Text + Python Guide Overview
Sublime Text + Python Guide Overview
Real Python
22 Python Code Review: Adding Pytest Tests to an Existing Python Web Scraper
Python Code Review: Adding Pytest Tests to an Existing Python Web Scraper
Real Python
23 Type-Checking Python Programs With Type Hints and mypy
Type-Checking Python Programs With Type Hints and mypy
Real Python
24 A Shorthand for Merging Dictionaries in Python 3.5+
A Shorthand for Merging Dictionaries in Python 3.5+
Real Python
25 Python Code Review Flask Web Security Tutorial + Virtualenvs, requirements.txt
Python Code Review Flask Web Security Tutorial + Virtualenvs, requirements.txt
Real Python
26 My Python Code Looks Ugly and Confusing – Help!
My Python Code Looks Ugly and Confusing – Help!
Real Python
27 Setting Up a Programmer Portfolio/Developer Blog – How To Get Started
Setting Up a Programmer Portfolio/Developer Blog – How To Get Started
Real Python
28 Do I Need a GitHub/GitLab/Bitbucket Profile as a Developer?
Do I Need a GitHub/GitLab/Bitbucket Profile as a Developer?
Real Python
29 Programmer Portfolio – Example and Walkthrough
Programmer Portfolio – Example and Walkthrough
Real Python
30 How to Get Your 1st Speaking Gig at a Tech Conference
How to Get Your 1st Speaking Gig at a Tech Conference
Real Python
31 How to Build Your Public Speaking Skills as a Developer
How to Build Your Public Speaking Skills as a Developer
Real Python
32 The Object-oriented Version of "Spaghetti Code" is "Lasagna Code" ?!
The Object-oriented Version of "Spaghetti Code" is "Lasagna Code" ?!
Real Python
33 Setting up Sublime Text for Python Developers – Lesson #1
Setting up Sublime Text for Python Developers – Lesson #1
Real Python
34 Cool New Features in Python 3.6
Cool New Features in Python 3.6
Real Python
35 "is" vs "==" in Python – What's the Difference? (And When to Use Each)
"is" vs "==" in Python – What's the Difference? (And When to Use Each)
Real Python
36 Emulating switch/case Statements in Python with Dictionaries
Emulating switch/case Statements in Python with Dictionaries
Real Python
37 Python Function Argument Unpacking Tutorial (* and ** Operators)
Python Function Argument Unpacking Tutorial (* and ** Operators)
Real Python
38 What Code Should I Put On My GitHub/GitLab/BitBucket Profile?
What Code Should I Put On My GitHub/GitLab/BitBucket Profile?
Real Python
39 A Crazy Python Dictionary Expression ?!
A Crazy Python Dictionary Expression ?!
Real Python
40 String Conversion in Python: When to Use __repr__ vs __str__
String Conversion in Python: When to Use __repr__ vs __str__
Real Python
41 Method Types in Python OOP: @classmethod, @staticmethod, and Instance Methods
Method Types in Python OOP: @classmethod, @staticmethod, and Instance Methods
Real Python
42 Optional Arguments in Python With *args and **kwargs
Optional Arguments in Python With *args and **kwargs
Real Python
43 Python Context Managers and the "with" Statement (__enter__ & __exit__)
Python Context Managers and the "with" Statement (__enter__ & __exit__)
Real Python
44 Installing Python Packages with pip and virtualenv / venv
Installing Python Packages with pip and virtualenv / venv
Real Python
45 "For Each" Loops in Python with enumerate() and range()
"For Each" Loops in Python with enumerate() and range()
Real Python
46 Python Code Review: LibreOffice Automation and the Python Standard Library
Python Code Review: LibreOffice Automation and the Python Standard Library
Real Python
47 Managing Python Dependencies With Pip and Virtual Environments – Lesson #1
Managing Python Dependencies With Pip and Virtual Environments – Lesson #1
Real Python
48 Python Tutorial: List Comprehensions Step-By-Step
Python Tutorial: List Comprehensions Step-By-Step
Real Python
49 Leveraging Python's Implicit "return None" Statements
Leveraging Python's Implicit "return None" Statements
Real Python
50 What's the meaning of underscores (_ & __) in Python variable names?
What's the meaning of underscores (_ & __) in Python variable names?
Real Python
51 Python Data Structures: Sets, Frozensets, and Multisets (Bags)
Python Data Structures: Sets, Frozensets, and Multisets (Bags)
Real Python
52 Writing automated tests for Python command-line apps and scripts
Writing automated tests for Python command-line apps and scripts
Real Python
53 How to find great Python packages on PyPI, the Python Package Repository
How to find great Python packages on PyPI, the Python Package Repository
Real Python
54 Immutable vs Mutable Objects in Python
Immutable vs Mutable Objects in Python
Real Python
55 PyPI vs Warehouse, the Next-Generation Python Package Repository
PyPI vs Warehouse, the Next-Generation Python Package Repository
Real Python
56 pep8.org — The Prettiest Way to View the PEP 8 Python Style Guide
pep8.org — The Prettiest Way to View the PEP 8 Python Style Guide
Real Python
57 My Experience at PyCon 2017 in Portland
My Experience at PyCon 2017 in Portland
Real Python
58 Pylint Tutorial – How to Write Clean Python
Pylint Tutorial – How to Write Clean Python
Real Python
59 "Reverse a List in Python" Tutorial: Three Methods & How-to Demos
"Reverse a List in Python" Tutorial: Three Methods & How-to Demos
Real Python
60 Python Refactoring: "while True" Infinite Loops & The "input" Function
Python Refactoring: "while True" Infinite Loops & The "input" Function
Real Python

This video teaches how to work with PDF files in Python, including extracting text, merging and concatenating files, and creating PDFs from scratch, as well as building hardware projects using a Raspberry Pi. It also covers topics such as Python package management, virtual environments, and async I/O.

Key Takeaways
  1. Use Python to extract text from PDF files
  2. Create PDF files from scratch
  3. Use SSH to connect to Raspberry Pi remotely
  4. Implement dependency injection for testing purposes
  5. Use mock or monkey patch to test date time functions
  6. Remove dependency on date time function and turn it into a parameter
  7. Use pip to install packages
  8. Use virtual environments with venv
  9. Use Docker to isolate and make environments reproducible and deployable
💡 Using Python to work with PDF files and building hardware projects using a Raspberry Pi can be done using various tools and techniques, including SSH, virtual environments, and async I/O.

Related Reads

📰
Microsoft said the patches would get bigger. I measured how much bigger.
Measure the impact of Microsoft's patches on Windows updates to understand the growth in size due to AI-powered vulnerability discovery
Dev.to · Erik Rekola
📰
The AI Paradox: Why Search Engines Still Need the Human Touch in 2026
Learn why human touch is still essential in search engines despite AI advancements in 2026
Medium · AI
📰
Looking Like You Know AI and Actually Knowing AI Are Two Different Things
Distinguish between superficial AI knowledge and genuine understanding to effectively apply AI in the workplace
Dev.to AI
📰
I Traced an AI Startup’s “10x Faster” Claim Back to Its Source
Learn to critically evaluate AI startup claims by tracing their sources and understanding the context behind benchmark numbers
Medium · Startup
Up next
PLATO Exoplanet Hunter Launch 2026 Searching for New Earths in a Warming World
Tech Folk Insights
Watch →