Using Powerful Language Features in Real-World Applications
Buch, Englisch, 605 Seiten, Format (B × H): 178 mm x 254 mm, Gewicht: 1163 g
ISBN: 978-1-4842-5792-0
Verlag: Apress
Some powerful aspects of Python are often documented with contrived examples that explain the feature as a standalone example only. By following the design and build of a real-world application example from prototype to production quality you'll see not only how the various pieces of functionality work but how they integrate as part of the larger system design process. In addition, you'll benefit from the kind of useful asides and library recommendations that are a staple of conference Q&A sessions at Python conferences as well as discussions of modern Python best practice and techniques to better produce clear code that is easily maintainable.
Advanced Python Development is intended for developers who can already write simple programs in Python and want to understand when it’s appropriate to use new and advanced language features and to do so in a confident manner. It is especially of use to developers looking to progress to a more senior level and to very experienced developers who have thus far used older versions of Python.
What You'll Learn
- Understand asynchronous programming
- Examine developing plugin architectures
- Work with type annotations
- Review testing techniques
- Explore packaging and dependency management
Zielgruppe
Professional/practitioner
Autoren/Hrsg.
Fachgebiete
Weitere Infos & Material
Chapter 1: Prototyping and Environments Chapter Goal: Create a prototype script to read a single sensor valueNo of pages 25Sub -Topics1 Introduce the example of collating data from a large number of othermachines1.1 Possible usecases of this pattern include log aggregation, servermonitoring, IoT, monitoring of customer servers, etc1.2 We’ll use raspberry pis with a mix of server monitoring andvery basic sensors like temperature sensors. There’ll be no IoTspecific setup or detail, it’s just that this is easier for people tofollow along with without inventing another system beingmonitored.1.3 There’ll be plenty of extra context here for how to apply theongoing example if you do already have a system that needsmonitoring.2 Prototyping using jupyter and nbconvert3 Use pipenv to set up dependency environment3.1 Note that by introducing pipenv before setuptools we’repreempting the confusion about the right way to do dependencyand environment management.
Chapter 2: Testing, Checking and LintingChapter Goal: Progress the prototype to a series of reliable functions thatcan be testedNo of pages: 30Sub - Topics1 Testing with PyTest (especially fixtures and MUT style)2 Type hinting and checking with mypy3 Linting with flake8 and autoformatting with black4 pre-commit and commit hooks5 GitHub CI integration for easier contributions
Chapter 3: Packaging ScriptsChapter Goal: Create an installable package that gives a single script toread the sensor valueNo of pages : 30Sub - Topics:1 setup.py and setuptools when it comes to packaging (not pip /setup.py for environment management, that’s in chapter 1)2 Namespace packages3 Console entrypoint4 argparseHelpful aside: Package name conflicts, installing from GitHub releases,release hashing, wheels
Chapter 4: From Script to LibraryChapter Goal: Extend the package to allow reading of multiple sensorsthrough the command lineNo of pages: 20Sub - Topics:1. Abstract Base Classes2. Second sensor value3. argparse subcommands
Chapter 5: Alternative InterfacesChapter Goal: Make the script functionality available as a HTTPmicroserviceNo of pages : 40Sub - Topics:1 Simple API servers using flask2 Plugin architecture using entrypoints3 Dynamic dispatch4 Serialisation considerations with custom classes (like units from pintspackage)
Chapter 6: Speeding Things UpChapter Goal: Discuss optimisation strategies, what the tradeoffs betweenasync and different types of caching are. We’ll use cachinghere, but async laterNo of pages : 25Sub - Topics:1 asyncio vs lru_cache vs redis vs sqlite etc2 Use of timeit3 File operations using context managers
Chapter 7: Aggregation ProcessChapter Goal: Create a new package, read configuration files, do a basicHTTP loopNo of pages : 25Sub - Topics:1 cookiecutter2 Config files (configparser vs json vs yaml)3 Requests library4 More depth in pytest usage
Chapter 8: Asynchronous ProgrammingChapter Goal: Understand the event loop, especially async for loops,demonstrate how it’s a good fit for the aggregation processNo of pages : 40Sub - Topics:1 Defining asynchronous functions2 Using the event loop3 Syntactic sugar for loops and iterators4 Async tasks vs await5 async executors
Chapter 9: Asynchronous DatabasesChapter Goal: Understand async executors, using sqlalchemy and JSONBNo of pages : 30Sub - Topics:1 sqlalchemy (and why pandas isn’t a good fit here)2 JSONB format and schemaless3 aiofile, asyncpg and usability/speed tradeoffs
Chapter 10: Viewing the DataChapter Goal: Creating Jupyter notebooks and using matplotlibNo of pages : 35Sub - Topics:1 Calling async functions from Jupyter Notebooks2 Binding function calls to ipywidgets for interactive reports3 Examples of matplotlib4 GeoJSON
Chapter 11: Fault ToleranceChapter Goal: Extending ABC interfaces and efficient use of iterables forlarge HTTP responsesNo of pages : 20Sub - Topics:1 Using __subclasshook__ effectively2 Chunked responses vs framing3 JSON deserialisation of partial data and efficient data transfer
Chapter 12: Callbacks and Data AnalysisChapter Goal: Using generators, iterators and coroutines for dataanalysis, async timeoutsNo of pages : 30Sub - Topics:1 Iterator based filtering2 Coroutine based plugins, for example a coroutine that pulls historicaldata and compares it to the current value to decide if an alarm shouldbe raised3 waitfor and executor timeout considerations




