Python Combat Guide
Python Combat Guide
A comprehensive manual about tricks, good practices and coding style for hands on Software Developer Managers and Developers
About the Book
Python Combat Guide
Is a practical guide, to setup projects from zero, or to improve existing ones.
Across 273 pages DIN A4, provides comprehensive tips and trick, nice todo and don't-do-this.
Is a very practical guide, covering many aspects, talking superficially about many things interesting things to know like using Docker, Jenkins, Puppet, Infrastructure as code, Blue/green, canary deployment, git... and going in deep to some good practices, with a lot of source code samples.
Explain how to setup Unit Testing with pytest from the scratch, PyCharm and does some practical TDD with examples.
What is it?
A very practical hands on manual for companies working with Python 3.6 (and Python 2.7).
I explain my experience working in several actual projects, different sizes and teach good practices.
Like the title suggest is a Combat Guide: read it and start crushing it!.
Is the Master Class that your best friend working in a multinational will teach you to help to improve how you and your Team work.
Having in consideration Operations Engineers, SRE and SysAdmins, it explains how to move from Procedural code to OOP, and how and why to use Interfaces and Base classes (Parent) and children (subclasses).
I use practical examples, and compare Bash and Python for different scenarios, and I show pytest Unit Testing from the scratch.
Probably you'll love it if you know Java or PHP cause in 5 hours will enable you to write code in Python.
I also provide a very simple Flask Web Application, so you see how easy it is, a simple SQLITE3 example, a simple GUI TKinter LDAP application, Cron Jobs that send email...
I release this guide during coronavirus quarantine, in Ireland.
This is a technical guide, intended to serve to all level of Developers and to SDMs (SDM - Software Development Managers).
Also useful for Team Leads and Project Managers..
It is not a basic manual, however I want to give a chance to non-tech people to learn how to program in Python, so they can get a good life or in the case of the scientists and academics that lost their jobs in the universities and need to go back to the market. Many of them use tools like Jupyter Notebook with Python, so they only need a Master Class to empower them to work in modern projects, with Git, Unit Testing, nice good practices, Team work...
What is not?
A typical manual to learn Python for beginners.
If you're looking for this, this is not your book.
Is focused on writing CLI programs, Crons and does not cover Django.
It is not a manual to learn specific Python language features in deep. Does not cover Python 3.7, 3.8 or 3.9 new features. Does not cover Django.
Neither explain Architecture Patterns like Event Queues or Microservices. Or how to write API's, there are many books for that.
It just go for pointing the effective way to build CMD Line applications, Crons, use Dependency Injection, and Unit Testing in a very professional way.
Also cover certain common sense aspects for working in Team, good practices, and some Scaling tricks.
So basically allowing SRE, DevOps and Managers to improve the way they run Command Line Appications, Server side scripting, Server Monitoring...
I think you will learn many useful things, but if you buy it and you are not satisfied, please feel free to return it. When you buy it you have a period of time to return it, which at the moment of this writing is 10 days. I only had one return, and it was a professional editorial that wanted to print the book in the States. But honestly, I like to keep all the rights and to be able to communicate with you and to update the book often. ;)
Is the code in gitlab?
Yes, most of the code is in gitlab, so you can download and just run it.
However is better to follow the book, as there are some errors intended, in order to show what not to do, and without reading the book you'll not understand it.
Even if you didn't buy the book, feel free to download the source code in gitlab:
- Dedication - p.2
- Thanks - p.2
- About this Combat guide - p.9
- About the author - p.9
- Disclaimer - p.9
- About coronavirus - p.10
- For the very beginners - p.10
- Hacker Rank - p.11
- About Floating point / decimals and Locale (international users) - p.12
- Why Python versus Bash (reasons for SRE) - p.13
- OOP vs Procedural code (SRE) - p.13
- A practical sample of OOP for the SRE world - p.15
- Why not Python 27? - p.19
- Few differences between Python 2 and 3 - p.19
- print() - p.20
- Use a printing method instead of calling directly print() - p.21
- Use of raw_input in classes - p.21
- Floats - p.21
- Floats in Databases and Currencies - p.22
- Things I don’t like from Python - p.25
- Tools - p.26
- IDE: PyCharm Professional - p.23
- CVS: GIT - p.23
- Unit Testing: PyTest - p.23
- Google Docs and google drive - p.24
- Working with GIT - p.24
- Gitlab - p.24
- Commit messages - p.24
- Commit messages for Gitlab - p.25
- Branches - p.27
- Branching Strategy - p.28
- Git flow - p.29
- GitHub flow - p.31
- Production branch with GitLab flow - p.32
- Environment branches with GitLab flow - p.33
- Release branches with GitLab flow - p.34
- Merge/Pull requests - p.35
- Feature branches - p.36
- Closing or Linking issues using comments in GitLab - p.36
- Removing feature branches after merge - p.37
- Have always backups from Master - p.37
- Git rebase - p.37
- Fetch - p.38
- Pull from the repo - p.38
- Pushing to the repo - p.38
- Keep an eye to new changes in commits through the Log section - p.39
- Never ever submit to the repo local changes you want to test - p.39
- Never commit Debug Lines - p.39
- Development Environment - p.40
- Use Linux - p.40
- Coding - p.41
- General Style - p.41
- PEP-8 - p.41
- MT Notation - p.41
- Short Code in Methods is preferred - p.43
- About ‘ or “ (apostrophe or double quote) - p.43
- Return - p.44
- Error code in return - p.45
- Predictability in return: Return always the same - p.45
- Files - p.45
- Operators - p.46
- Tabs or spaces - p.46
- Space to breath - p.47
- Too much compressed code - p.47
- Use parentheses, Luke - p.49
- Do not use Global variables - p.50
- Declare variables on top of the Method - p.50
- Class Names - p.54
- Class Constants - p.54
- Comparing with constants - p.55
- Properties - p.55
- Properties and variables defined on top of the Method - p.55
- Functions and Methods - p.56
- Do not print inside classes, use the capacity of Python to return more than a parameter
- instead - p.56
- Warning: Do not repeat Method of Function names - p.57
- Function/Method Parameters with a default value (Keywords) - p.57
- Keyword Argument for a Method/Function - p.58
- Type Hinting and Annotations - p.61
- Lists, Arrays, Dicts, Tuple - p.62
- Mixed power of Lists, Dicts - p.62
- Dynamic grow - p.63
- “in” very important check to do - p.63
- Convenience of having a method for checking “in” - p.63
- Default dict, to save memory - p.64
- Sort a List by key - p.66
- Arrays and index -1 - p.66
- Expect the unexpected - p.66
- Use getters and setters - p.67
- Use update_ for methods that update Objects, not get_ - p.68
- Jumps of line \n to the end - p.69
- If / else - p.70
- Else in loops - p.71
- Careful String evaluations - p.71
- Calling variables by name in Methods or Functions - p.72
- If for text properties - p.72
- Avoid repeating code - p.73
- Comments - p.74
- Python doc - p.74
- Document - p.74
- No dead code - p.75
- We avoid Magic Methods - p.75
- Avoid using yield, avoid using lambdas - p.76
- Avoid using list comprehensions - p.76
- Avoid using Regular Expressions, unless you know what you are doing - p.76
- Creating Web Services with Flask - p.77
- Files for holding Data Structures and Databases - p.78
- Collation - p.78
- Data types in the Database - p.78
- Prefixes: MT Notation - p.80
- Expect the Unexpected - p.82
- Corner cases and assumptions - p.82
- Do no escape to shell to run a program, if you can do it from Python - p.82
- Try to have Common Libraries for the Common Tasks - p.83
- Bug fixing - p.84
- Focus, make sure you don’t do mistakes - p.84
- Better Quality than Quantity - p.84
- Cross Testing - p.84
- Check the Logs - p.85
- Methodology - p.88
- Methodology serves a purpose - p.88
- We are modern heroes - p.88
- Deploying to Production - p.88
- Create a Deploy or Launch or Change Request Document in the issue tracker - p.88
- Deploying to Production using immutable Docker Containers and/or Microservices - p.89
- Running in Production - p.91
- Check for Log Errors regularly in Production Servers - p.91
- Profiling - p.91
- Forensics / Postmortem analysis - p.91
- Do not use Database Stored Procedures - p.91
- Webservices and API are good, microservices are not always the wisest choice - p.92
- Blue green Deployment vs Canary, and Rolling Upgrade - p.93
- Managing the Team - p.95
- Managing takes time - p.95
- Synchronizing the knowledge of the Team - p.95
- Demos and Share the Pain - p.95
- Be always fair - p.96
- Automated Code Testing - p.98
- Unit Testing Framework - p.98
- Tests are not optional - p.98
- Run the Unit Tests - p.98
- Run tests frequently - p.98
- Do not reuse other Tests - p.98
- Importance of running Tests (Unit Testing Tests) - p.99
- Emails in the Tests - p.100
- Testing Infrastructure as Code - p.101
- Managing the Team - p.101
- Allow to learn and creativity - p.101
- New members join the Team - p.102
- Kick Off Meeting - p.102
- Concentrated advice for my Team - p.102
- Methodology for the Development, Presentations, Documents and Demos - p.103
- Prepare Demos: name Objects and Variables - p.103
- Prepare Demos: prepare it in advance and test that everything works - p.103
- Take care of the details - p.103
- We don’t avoid confronting problems - p.104
- We document and write Functional Analysis - p.104
- Checking the Functional Analysis before starting programming - p.105
- We reply the emails - p.105
- We do Stand up Meetings - p.105
- Exercises for Candidates / New Recruitments - p.105
- Tools to discuss remotely (screener) - p.106
- First, the FooBar exercise - p.106
- Second, Power of 2 exercise - p.106
- What we take in consideration from the candidate? - p.106
- Being nice - p.107
- Fair Questions for Developers - p.107
- Working with pytest Unit Testing - p.107
- Installing pytest in Ubuntu - p.108
- Installing pytest for Python2 - p.108
- Installing pytest for Python3 - p.108
- Running the Tests in a Virtual Machine like VirtualBox - p.108
- Running the Tests in a Docker container - p.108
- Location of the code samples and tests - p.109
- Writing the first test - p.110
- Using classes for testing - p.110
- Testing a real class - p.112
- Extending our first test - p.113
- Extending a bit more and getting errors - p.114
- Fixing our Test using TDD - p.117
- Advantages and disadvantages of having everything in one single method - p.119
- Reusability - p.121
- Adding improvements discussed - p.122
- Creating unit testing for DiskUtils - p.123
- Adding pytest to PyCharm Community Edition - p.125
- Code Coverage - p.128
- Adding Dependency Injection - p.131
- Stubs and Mocks and Monkeypatching - p.136
- Putting all together - p.141
- Exercises - p.148
- Refactors - p.149
- Fixtures - p.149
- Fixture to patch timesleep - p.150
- Pytest config file conftestpy - p.152
- Testing Exceptions - p.154
- Catching an expected Exception - p.154
- Code Coverage on Exceptions - p.154
- Tricks and Appendix - p.160
- A mix: Unit Testing on actual Hardware - p.160
- Convert a Python program to a Cron - p.161
- Class FileUtils - p.165
- Class SmtpUtils - p.171
- Exercises - p.174
- Different ways of doing things - p.174
- Exercises - p.177
- Printing in color to the Linux Terminal - p.182
- Working with SQLITE3 - p.185
- Thinking about the decision of designing Interfaces and Base Classes extended - p.190
- The boring theory - p.190
- Practical approach - p.191
- Practical approach for SRE - p.198
- CTOP.py A sample of a program that includes all these lessons - p.178
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Ansible for KubernetesJeff Geerling
Ansible is a powerful infrastructure automation tool. Kubernetes is a powerful application deployment platform. Learn how to use these tools to automate massively-scalable, highly-available infrastructure.
Practical FP in Scala: A hands-on approachGabriel Volpe
A practical book aimed for those familiar with functional programming in Scala who are yet not confident about architecting an application from scratch.
Together, we will develop a purely functional application using the best libraries in the Cats ecosystem, while learning about design patterns and best practices.
Functional Design and ArchitectureAlexander Granin
Software Design in Functional Programming, Design Patterns and Practices, Methodologies and Application Architectures. How to build real software in Haskell with less efforts and low risks. The first complete source of knowledge.
Production HaskellMatt Parsons
Are you excited about Haskell, but don't know where to begin? Are you thrilled by the technical advantages, but worried about the unknown pitfalls? This book has you covered.
Tame your Work FlowSteve Tendon and Daniel Doiron
Do you need a high performance enterprise governance approach improving management, execution and delivery while dealing with multiple projects/products, events, stakeholders and teams? Giving you better bottom line results, faster time to market, less work, better predictability, happier employees, and delighted clients? Then learn about TameFlow!
Ansible for DevOpsJeff Geerling
Ansible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Machine Learning EngineeringAndriy Burkov
"If you intend to use machine learning to solve business problems at scale, I'm delighted you got your hands on this book."
—Cassie Kozyrkov, Chief Decision Scientist at Google
"Foundational work about the reality of building machine learning models in production."
—Karolis Urbonas, Head of Machine Learning and Science at Amazon
C++ Best PracticesJason Turner
Level up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Composing SoftwareEric Elliott
All software design is composition: the act of breaking complex problems down into smaller problems and composing those solutions. Most developers have a limited understanding of compositional techniques. It's time for that to change.
El Manual del ManagerKeyvan Akbary, Félix López, and Álvaro Salazar
¿Has deseado alguna vez el haber tenido una buena introducción al rol del Engineering Manager? En este libro aprenderás lo necesario para ejercer el rol de una manera efectiva: Expectativas y Responsabilidades del Rol, 1-1s, Ayudar a Crecer, Objetivos, Planes de Carrera, Cultura, Feedback, Contratación, Cultura de Producto y mucho más.
The Tester's Library
8 BooksThe Tester's Library consists of eight five-star books that every software tester should read and re-read. As bound books, this collection would cost over $200. Even as e-books, their price would exceed $80, but in this bundle, their cost is only $49.99. Here are the books, and why they should be in your library: Perfect Software and Other...
11 BooksIn this bundle, you will find 10 different agile books. They are about different aspects of being agile. - finding a job - doing coding dojo's - Retrospectives - Personal kanban - a non-typical coaching book and even a book that gives you an insight in the lives of some agile people.
WTFlop 6M + HU - Beta Bundle
Marionette.js A to Z
Build A Better Backbone App
3 BooksThe best way to learn new development skills is through experience, but that takes time you don't have.Get the best of both worlds with this bundle: you'll learn how to produce modern web applications by learning from experienced developers like Derick Bailey and David Sulc. BackboneJS is one of the favorite tools on the web today, but it...
General Systems Thinker Bundle
5 BooksThe General Systems Thinker Bundle is just that: a bundle of five books to advance the reader one giant step toward improved thinking, based on General Systems principles. Four of the books are the complete General Systems Series. The fifth is fictional piece which shows some general systems thinkers in action. It's a mystery in which a group of...
Experiential Learning Bundle
4 BooksThis bundle provides all four volumes of the popular Experiential Learning Series at a savings of $20 over the price if purchased separately.
2 BooksAfter getting up and running with Ansible in Jeff Geerling's Ansible for DevOps, strengthen your skills managing tens to thousands of instances and services in Amazon's AWS cloud with Yan Kurniawan's Ansible for AWS.
Learn ECMAScript 6 inside and out
2 BooksFor any technology, it helps to get multiple points of view on the functionality to get the best possible understanding. For ECMAScript 6/2015, no two resources are recommended more frequently thanExploring ES6by Dr. Axel Rauschmayer andUnderstanding ECMAScript 6by Nicholas C. Zakas. These two points of view, investigating the specification and...
Software architecture, for systems old and new
2 BooksThis bundle includes books about hands-on software architecture.