PyBites Python Tips

91 ratings

250 Bulletproof Python Tips That Will Instantly Make You A Better Developer

Pythonista, how many Python tricks do you have up your sleeve?

Are you tired of reading through long tutorials where you’ve lost interest by the time you get to the actual code or meat of the subject?

Are you so overwhelmed by the richness of the Python language that you’re finding it difficult to learn the many different branches?

Do you wonder how you can make your code more elegant, maintainable and Pythonic?

This was certainly us when we started our Python journeys!

One of Python’s strengths is that while it’s so deep and technical it’s also a wonderful entry level programming language. This contrast though can be paralyzing for folks that want to go from doing things the “basic way” to doing things .

There is an answer however and we have a solution that will once and for all make things more accessible for you. Read on to hear more... or just buy the book! We don’t mind either way!

PyBites Tips


This book contains small, practical pieces of Python code that will boost your knowledge of the language.

We quickly realised that the sooner you start reading and applying code, the quicker you progress.

As a result we’ve distilled almost 4 years of PyBites into a rich collection of tips that are insightful, practical, fun and presented in such a way that you can get straight to coding with them.

You’ve probably seen some of these on social media in the last couple of years. They’ve helped thousands of developers worldwide improve their Python skills so we know they’re good.

These tips have reminded developers of Pythonic ways of doing things and why Python is such a great language to code in.

"I love these tips as they remind me of the #pythonic way to do things" - David Colton

What’s inside?

Let’s take a quick tour.

Firstly, you can consume the book in any order. Just pick out the topics you want to learn about or need the most at any given time.

We’re always trying to battle the widespread tutorial paralysis we commonly see in the industry. That is NOT the experience we want you to have with us.

Construct dictionaries

Head over to page 18 and you will learn how to construct a dictionary from 2 iterables ().

Powerful sorting options

On page 28 you will discover how to sort any sequence by a callable you define. Your sorting skills will never be the same again ().

Sentiment analysis

On page 35 you will learn about an exciting module to do sentiment analysis on a bunch of tweets.

Yes, these tips go far beyond Python’s standard library. You’ll even learn some Django.

Builtins you want to know about

We are showing you a lot of built-ins that will make your life easier and your code more idiomatic.

Head over to page 39 to learn about two elegant one-liners thanks to any and all.

Getting help

On page 45 we show you some invaluable ways to inspect objects in Python, an unmissable skill for any Python developer.


Starting page 50 you will find two recipes to make an infinite iterator followed by how to get all combinations from a list.

This module is so awesome! It helps you to chain iterables (page 32), combine sequences of different length (page 157), even slice a generator (page 169). The itertools module occurs in no less than 13 tips!

What’s up with __main__?

We also care about the newer Pythonistas.

If you’ve wondered what if __name__ == “__main__” is about, we’ve got you covered on page 66.

Or what about an entry point to a package? We cover too on page 261.

OOP techniques

A lot of folks we talk with see OOP as THE magic they need to know to become proficient at Python. And they are partly right.

We have several tips that cover this. On page 58 you’ll see that everything is an object in Python ().

On pages 70 and 108 we talk about object representation and how it helps debugging.

OOP is really everywhere in the language and on page 75 you see a different dict constructor at work.

Or what about powerful Path (pathlib) methods which you’ll see on page 78?

On page 92 you’ll learn about the callable and getattr built-ins, and similarly on page 107 you will learn about attrgetter from the operator module.

You will live and breathe properties with tips 101 and 139!

Finally, do a search on “class” and you will see quite a few of them.

We hope this covers enough OOP for starters ;)


We go beyond Python by showing you some powerful tools.

On page 80 we create a gif image using the imageio library.

Then on page 87 you’ll learn about the cool howdoi tool to search for code snippets using the command line.

On page 113 you will learn about Django extensions.

What about dependencies? We cover a tool called pipdeptree on page 245.

We even post a (Github) gist using requests on page 233.

Or what if you can run some startup code before dropping into the REPL? We show you hose to use the PYTHONSTARTUP env variable on page 258. 

We even get down to the bytecode using the dis module on page 244.

How __all__ can save you

We also think about people writing modules for other developers’ consumption.

On page 97 you will learn about a technique to encapsulate your code so that even somebody doing an import * won’t see all your stuff ...

Robust testing techniques

We are keen on writing test code so expect to find many pytest / testing related tips in the book:

- On page 101 you will learn how to make your test code more DRY (don’t repeat yourself)

- On page 102 you learn how to mock out web services in your tests (similarly on page 51 you will learn how to cache API calls).

- On page 109 you will learn about the assert_called_with method.

- On page 110 you will learn how to access an exception string caught by pytest.raises.

- On page 115 you will learn about how to test datetimes.

- On page 150 you will learn about pytest's killer feature to manage setup / teardown code: fixtures

- On page 160 you will learn how to tactically skip a test based on a condition.

- On page 183 we show you the useful tmp_path fixture.

- On page 214 we show you how to debug a hanging test.

- On page 222 we show how to make your tests more readable.

- On page 227 we show you how to test logging.

- On page 249 we work around testing floats.

- And on page 257 we show how you can organize your fixtures

We even show you how to use Selenium on page 231.

Powerful data structures

Have you heard about the collections module?

If not, time to get to know it! There are no less than 12 tips dedicated to this awesome module.

On page 34 (and 165) we'll meet the awe inspiring Counter container, on page 106 we show you when to use a deque over a list. 

Page 147 shows some of its wrappers to make your own data types. On page 163 you'll learn about namedtuples. And last but not least tips 80 and 147 are dedicated to defaultdicts.

Useful datetime methods

On page 62 we look at the calendar module which made it relatively easy to build our (Seinfeld) coding streak calendar on our platform.

You will learn about fuzzy parsing using the powerful dateutil library on page 105.

And you will learn about what day of the week, and what week of the year it is on pages 119 and 120.

We use the powerful timedelta in tips 101 and 108. There are 17 tips that use the datetime module!

Speed up downloads

On pages 143-145 we'll introduce you to concurrent.futures speeding up web downloads tremendously. We'll use the timeit module to measure performance. And we round things off introducing you to a tool to make a beautiful progress bar.

Python 3.9 coverage

On pages 134-138 we got 5 tips dedicated to new Python 3.9 features. No more excuses: use the latest and greatest version of Python!


Well rounded Pythonistas know their generators :) - no worries, we got your back here too! On page 128 we share a date generator we still use today to create WINS files. And on page 168 you will learn about "yield from" for even more concise generators.

Data validation

We show you how to validate JSON on page 79.

On page 242 we show you an awesome module to validate data based on type annotations: pydantic. 

Or what about ip addresses? On page 255 we validate them with the ipaddress and socket modules.

Decorators and context managers

On pages 266-267 we show you some practical decorators (timing and retrying a function) you can immediately start using. 

On pages 170 and 215 we use context managers to rollback a transaction and connect to a DB. But the contextlib module does not stop there, we also show you how to redirect standard output (page 65) and suppress an exception (page 260).

The Standard Library inside out!

After hitting the low hanging fruit, we go deeper and discover lesser known (or used) modules like shlex, getpass, uuid, zipfile and operator. 

With 66 Standard Library modules you will learn Python inside out! And if that's not enough we introduce you to 33 PyPI modules as well.


We hope you’ll agree by now that there is a lot to learn.

We’re actually positively surprised we were able to fit this into just 279 pages!

And as our tips are so practical, we cannot wait to see you putting all of this into your own code.

Tip #27. Copy.deepcopy


This brings us to the exercising part.

Where relevant we have linked exercises you can take on our coding platform.

Remember: retention increases 3-5 fold when you put what you learn into practice.

We even recommend you teach what you learn here to benefit from a 10X retention rate.

Tip #10. Is vs == (object equality)

How our community experiences our tips

Our tips are widely acclaimed by the Python community as being revealing, helpful, insightful, Pythonic, practical (they can be implemented immediately in one’s code base), and fun.

"Did you know as of 3.6 you can use underscores in your large numbers? Me either! - Chris Williams (Thanks Chris! - Julian)

- Geoff R

- Sergio S

- Beth B

- Alex K

- Andreas J

- Daniel H

- Israel L

- Jesse B

– Andrew J

- Bart H

- Anthony L

- Chris W

- David C

- Gabriel S

- Ed G

- Wilson U

Try it yourself, at our risk

We believe so strongly in this book and the gold within that we’re willing to take the full risk.

If, after reading it, you find you’ve not learned at least 1 or 2 new things (within 30 days of purchase), we’ll happily refund you the complete price of the book. No questions asked AND you get to keep the book.

Lock in future updates

But there’s more!

You’re actually going to get many more tips over the coming months!

Although the current collection of 250 tips is already profound and will surely help you up your game, by buying this product you will lock in any future updates, even as we increase the price.

For your investment of $7.99 USD today, you will actually end up owning 300 quality tips over the lifetime of the book. As we add more tips to the book though, we will be increasing the price so make sure you lock in your future updates at this introductory launch price.

What are you waiting for?

Enough reading (of this page)! Scroll back to the top and click the "I want this" button now!


Who is this book for?

Anyone interested in Python. The book may have more intermediate concepts but if you're a beginner, being exposed to these libraries, tools and concepts is going to get you experience with the language  faster.

Why is the Kindle version slower to launch?

It takes time to convert the base eBook/PDF version to Kindle (.mobi) format. In an effort to get you the eBook quicker we push it out first while the Kindle version is being created.

Will there be a print version?

Eventually, yes. As we mentioned above, we will be adding tips to the eBook over time. We're refraining from publishing a physical, print book until all tip updates have been made. This will avoid people having to purchase the print book again and again just to get the updates.

Why the super low price?

We wanted to make this content accessible to as many people as possible all over the world. The "low" price allows people in countries where currencies aren't as strong to access the value within.

Why was I given license key when I purchased the book?

Treat this license key like you would the key you receive when you purchase a software product. This is your proof that the "copy" of the book you have is yours. No need to register it anywhere, just keep it a record of it.

Are the exercises mentioned in the book included?

The short answer is no.

On occasion we mention a "Bite Exercise" on our platform as related material. This link takes you to our Python Challenges platform which is subscription based. If you have an active subscription you'll be able to starting coding the exercise right away. If not, you'll be able to create an account and activate a two week free trial to access the exercise.

Tip #14. Collections.Counter

Tip #76. Logging debug info

I want this!

eBook with 250 Real World PyBites Python Tips


(91 ratings)
5 stars
4 stars
3 stars
2 stars
1 star

PyBites Python Tips

91 ratings
I want this!