As long as you give proper attribution, you are not plagiarizing.
You could be violating copyright if you use code verbatim that is not licensed to you for the purpose you are using it, but it seems likely to me that the code in an educational book would have a pretty broad license.
However, you should definitely check with the person who is advising your thesis about expectations for your thesis. A bigger problem for you is that a thesis project is usually expected to have quite a bit of originality. Even if it's a collection of things that have already been done (a review/survey sort of paper), the expectation is likely that the collection part is novel/your own work: the part where you decide what to include. If you're working almost entirely from one source, you're not really doing much collecting to add value to your thesis. On the other hand, if these are just some necessary programming "pre steps" that get you towards the actual work you're doing, that may be totally fine. Ask your advisor. I'd also consider that if someone has written a book to show how to implement this thing, there's probably an existing Python package available open source that you could work from, instead, which would save you time and let you focus on the important parts.
It's not plagiarism to hand someone an entire Stephen King novel if you are clear and honest about saying "This entire book was written by Stephen King, and the only thing I've done is to obtain it from the library and hand it to you", but it won't earn you credit for completing a bachelor's thesis, either.