Thursday, July 22, 2021

Python Bytes: #243 Django unicorns and multi-region PostgreSQL

<p><strong>Watch the live stream:</strong></p> <a href='https://www.youtube.com/watch?v=vvuLoFFx-FI' style='font-weight: bold;'>Watch on YouTube</a><br> <br> <p><strong>About the show</strong></p> <p>Sponsored by <strong>us:</strong></p> <ul> <li>Check out the <a href="https://training.talkpython.fm/courses/all"><strong>courses over at Talk Python</strong></a></li> <li>And <a href="https://pythontest.com/pytest-book/"><strong>Brian’s book too</strong></a>!</li> </ul> <p>Special guest: <a href="https://twitter.com/simonw"><strong>Simon Willison</strong></a></p> <p><strong>Michael #1:</strong> <a href="https://www.mongodb.com/blog/post/launched-today-mongodb-5-0-serverless-atlas-evolution-application-data-platform"><strong>MongoDB 5</strong></a></p> <ul> <li><strong>Native Time Series</strong>: Designed for IoT and financial analytics, our new time series collections, clustered indexing, and window functions make it easier, faster, and lower cost to build and run time series applications</li> <li>MongoDB automatically optimizes your schema for high storage efficiency, low latency queries, and real-time analytics against temporal data.</li> <li><strong>The Versioned API</strong> future-proofs your applications. You can fearlessly upgrade to the latest MongoDB releases without the risk of introducing backward-breaking changes that require application-side rework</li> <li><strong>New MongoDB Shell</strong> we have introduced syntax highlighting, intelligent auto-complete, contextual help and useful error messages creating an intuitive, interactive experience for MongoDB users (use <code>mongosh</code> rather than <code>mongo</code> on the CLI).</li> <li>Also launched preview release of serverless instances on MongoDB Atlas</li> <li>You can <a href="https://www.youtube.com/watch?v=OQJHf8xdDRM"><strong>watch the MongoDB keynote here</strong></a>.</li> </ul> <p><strong>Brian #2:</strong> <a href="https://docs.python.org/3.11/whatsnew/3.11.html#enhanced-error-locations-in-tracebacks"><strong>Python 3.11 : Enhanced error locations in tracebacks</strong></a></p> <ul> <li>Yes, 3.11. Even though 3.10 is still in Beta, we’re already excited about 3.11</li> <li>tracebacks now point to the exact expression that caused the error within the line:</li> </ul> <pre><code> Traceback (most recent call last): File "distance.py", line 11, in [HTML_REMOVED] print(manhattan_distance(p1, p2)) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "distance.py", line 6, in manhattan_distance return abs(point_1.x - point_2.x) + abs(point_1.y - point_2.y) ^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'x' </code></pre> <ul> <li>even deeply nested calls</li> </ul> <pre><code> Traceback (most recent call last): File "query.py", line 37, in [HTML_REMOVED] magic_arithmetic('foo') ^^^^^^^^^^^^^^^^^^^^^^^ File "query.py", line 18, in magic_arithmetic return add_counts(x) / 25 ^^^^^^^^^^^^^ File "query.py", line 24, in add_counts return 25 + query_user(user1) + query_user(user2) ^^^^^^^^^^^^^^^^^ File "query.py", line 32, in query_user return 1 + query_count(db, response\['a'\]['b']\['c'\]['user'], retry=True) ~~~~~~~~~~~~~~~~~~^^^^^ TypeError: 'NoneType' object is not subscriptable </code></pre> <ul> <li>and math expressions:</li> </ul> <pre><code> Traceback (most recent call last): File "calculation.py", line 54, in [HTML_REMOVED] result = (x / y / z) * (a / b / c) ~~~~~~^~~ ZeroDivisionError: division by zero </code></pre> <p><strong>Simon #3:</strong> <strong>fly.io</strong> <a href="https://fly.io/docs/getting-started/multi-region-databases/"><strong>multi-region PostgreSQL</strong></a> and <a href="https://fly.io/blog/last-mile-redis/"><strong>last mile Redis</strong></a></p> <ul> <li>fly.io are a hosting provider that specialize in running your code in containers that are geographically close to your users</li> <li>What I find interesting about them is that they are taking something that used to be INCREDIBLY hard - like geographically sharding your database - and describing patterns for doing that which make it easy-enough that I might actually do it</li> <li>Their writing is really good. I’m learning a ton from them about designing code to run globally that applies even if I don’t end up using their service</li> </ul> <p><strong>Michael #4:</strong> <a href="https://www.django-unicorn.com/"><strong>django-unicorn</strong></a></p> <ul> <li>A magical full-stack framework for Django</li> <li>Quickly add in simple interactions to regular Django templates without learning a new templating language. </li> <li>Building a feature-rich API is complicated. Skip creating a bunch of serializers and just use Django. </li> <li>Early days if you want to contribute</li> </ul> <p><strong>Brian #5:</strong> <a href="https://blue.readthedocs.io/en/latest/"><strong>Blue : The somewhat less uncompromising code formatter than</strong></a> <a href="https://blue.readthedocs.io/en/latest/"><strong>black</strong></a></p> <ul> <li>Suggested by Chris May</li> <li>Code from Black, mods by Grant Jenks and Barry Warsaw</li> <li>It’s not a fork, it’s a patched version of black. Kind of a “containment over inheritance” thing.</li> <li>Deltas: <ul> <li>blue defaults to single-quoted strings. <ul> <li>except docstrings and triple quoted strings (TQS). Those are still double quotes.</li> </ul></li> <li>blue defaults to line lengths of 79 characters. black is 88.</li> <li>line lengths are customizable with all related tools.</li> <li>blue preserves the whitespace before the hash mark for right hanging comments. <ul> <li>making comment blocks off to the side possible</li> </ul></li> <li>blue supports multiple config files: pyproject.toml, setup.cfg, tox.ini, and .blue.</li> </ul></li> <li>Interesting quote from the docs: “We’d prefer not to fork or monkeypatch. Instead, our hope is that eventually we’ll be able to work with the <code>black</code> maintainers to add just a little bit of configuration and merge back into the <code>black</code> project. “</li> <li>My take <ul> <li>Probably stick with black most of the time. </li> <li>For some large exiting projects with lots of strings that have standardized to single quote strings already, black is jarring. </li> <li>Also, strings with double quotes in them are untouched by black, so if you have lots of those, strings will be inconsistent, making the code harder to read and confusing to maintain.</li> <li>And the choice isn’t really black or blue. It’s often nothing due to the non-starter of switching to double quote strings by default. blue is better than nothing.</li> </ul></li> <li><a href="https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html">See also</a> <a href="https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html"># fmt: off</a><a href="https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html">,</a> <a href="https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html"># fmt: on</a> <a href="https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html">for both blue and black</a></li> </ul> <pre><code> # tell black/blue to not reformat this table # fmt: off some_table = [ 1, 2, 3, 100, 200, 300 ] # fmt: on </code></pre> <p><strong>Simon #6:</strong> <a href="https://alexn.org/blog/2020/11/11/organize-index-screenshots-ocr-macos.html"><strong>Organize and Index Your Screenshots (OCR) on macOS</strong></a></p> <ul> <li>I’ve been wanting to figure out how to use Tesseract OCR for years, and this post finally unlocked it for me</li> <li>brew install tesseract</li> <li>tesseract image.png output-file -l eng pdf</li> <li>(use txt instead of pdf to get plain text)</li> <li>I wrote a TIL about this at https://ift.tt/3zoBWfk> <li>It’s really good! Even works against photos I’ve taken. And the PDFs it produces have copy-and-paste text in them (despite looking visually identical to the image) and can be searched using Spotlight.</li> <li>There’s a pytesseract library but it actually just works by running that Tesseract CLI tool <a href="https://github.com/madmaze/pytesseract/blob/31973a4c58ad7d871f6b6b4cae1aa3f2f29d6b43/pytesseract/pytesseract.py#L252">in a subprocess</a></li> <li>Extra: <a href="https://simonwillison.net/2020/May/21/dogsheep-photos/">Using SQL to find my best photo of a pelican according to Apple Photos</a></li> </ul> <p><strong>Extras</strong></p> <p>Michael:</p> <ul> <li>Strong Typing follow up <ul> <li>typed nametuple: <a href="https://strongtyping.readthedocs.io/en/latest/namedtuple/">strongtyping.readthedocs.io/en/latest/namedtuple/</a></li> <li>now classes: <a href="https://github.com/FelixTheC/strongtyping/issues/65">github.com/FelixTheC/strongtyping/issues/65</a></li> </ul></li> <li>We are <em>finally</em> rid of tracking on the podcast sites. But it took some neat tech work</li> </ul> <p><strong>Simon</strong></p> <ul> <li><a href="https://pythonbytes.fm/episodes/show/237/separate-your-sql-and-python-asynchronously-with-aiosql">https://pythonbytes.fm/episodes/show/237/separate-your-sql-and-python-asynchronously-with-aiosql</a> talked about Textual but it’s worth marveling at how far along it has already come, one of the fastest pieces of development-in-the-open I’ve ever seen - follow along on Will’s Twitter account, he posts a lot of videos and screenshots e.g. https://twitter.com/willmcgugan/media and the videos in his README at https://ift.tt/2UD6JX2> </ul> <p><strong>Joke</strong> </p> <p><a href="https://twitter.com/Spirix3/status/1410564231897006082"><strong>A “Query tale”?</strong></a></p> <p>Song from Brett Cannon (take on <a href="https://www.youtube.com/watch?v=qzZmU0aGmcc"><strong>Pinky and the Brain theme song</strong></a>)</p> <ul> <li><em>What do you want to do today, Brian?</em></li> <li><em>Same thing we do every Wednesday, Michael. Help Python take over the world.</em></li> <li><em>It's Michael and the Brain!</em></li> <li><em>Yes, Michael and the Brain!</em></li> <li><em>One's into testing, the other GUIs!</em></li> <li><em>They're both into making Python seem sane!</em></li> <li><em>They're Michael,</em></li> <li><em>they're Michael and the Brain, Brain, Brain, Brain, Brain!</em></li> </ul>

from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...