Wednesday, December 23, 2020

Python Bytes: #213 Uh oh, Vulcans have infiltrated Flask

<p>Catch the <strong>video edition live stream</strong> on YouTube: <strong><a href="https://www.youtube.com/embed/5noeLbjTz_o">Recording out here</a></strong>.</p> <p>Sponsored by us! Support our work through:</p> <ul> <li>Our <a href="https://training.talkpython.fm/"><strong>courses at Talk Python Training</strong></a></li> <li><a href="https://testandcode.com/"><strong>Test &amp; Code</strong></a> Podcast</li> <li><a href="https://www.patreon.com/pythonbytes"><strong>Patreon Supporters</strong></a></li> </ul> <p>Special guest: <a href="https://twitter.com/anthonypjshaw/"><strong>Anthony Shaw</strong></a></p> <p>Be part of the episode by subscribing and “smashing that bell” over at <a href="http://pythonbytes.fm/youtube"><strong>pythonbytes.fm/youtube</strong></a></p> <p><strong>Michael #1:</strong> <a href="https://github.com/arrobalytics/django-ledger"><strong>Django Ledger Project</strong></a></p> <ul> <li>by Miguel Sanda</li> <li>The mission is to provide free and open source accounting software that could easily replace commercial alternatives like QuickBooks.</li> <li>Django Ledger supports: <ul> <li>Chart of Accounts.</li> <li>Financial Statements (Income Statement &amp; Balance Sheets).</li> <li>Automatic financial ratio &amp; insight calculations.</li> <li>Multi tenancy.</li> <li>Hierarchical entity management.</li> <li>Self-contained Ledgers, Journal Entries &amp; Transactions.</li> <li>Financial Activities Support (operational/financial/investing).</li> <li>Basic OFX &amp; QFX file import.</li> <li>Bills &amp; Invoices with optional <em>progressible</em> functionality.</li> <li>Basic navigational templates.</li> <li>Entity administration &amp; entity manager support.</li> <li>Bank Accounts.</li> </ul></li> <li>Not <em>quite</em> ready for production.</li> <li><strong>This project is actively looking for contributors. Any financial and/or accounting experience is a big plus.</strong> If you have prior accounting experience and want to contribute, don't hesitate to contact.</li> <li>Browse the screenshots on the github repo.</li> </ul> <p><strong>Brian #2:</strong> <a href="https://github.com/mikeabrahamsen/Flask-Meld"><strong>Flask-Meld:</strong></a> <strong>simple JavaScript interactive features without all of the JavaScript.</strong></p> <ul> <li><a href="https://michaelabrahamsen.com/posts/flask-meld-ditch-javascript-frameworks-for-pure-python-joy/">Flask-Meld article with example</a> <ul> <li>Michael Abrahamsen, <a href="https://twitter.com/mikeabrahamsen">@MikeAbrahamsen</a></li> <li><a href="https://meld.conveyor.dev/">working example</a>, <a href="https://github.com/mikeabrahamsen/Flask-Meld-Example">code for example</a></li> <li>It seems really zippy. Definitely gonna try this.</li> </ul></li> <li>Similar project for Django: <a href="https://www.django-unicorn.com/">django-unicorn</a> <ul> <li>Adam Hill, <a href="https://twitter.com/adamghill">@adamghill</a></li> <li><a href="https://www.django-unicorn.com/documentation/examples/todo">todo example</a></li> </ul></li> </ul> <p><strong>Anthony #3:</strong> <a href="https://realpython.com/python-bitwise-operators/"><strong>Bitwise operators in Python</strong></a> <strong>(RealPython)</strong></p> <ul> <li>Article by <strong>Bartosz ZaczyƄski</strong></li> <li>Particularly useful for the <code>enum.IntFlag</code> and <code>enum.Flag</code> classes in the stdlib since 3.7</li> </ul> <pre><code> &gt;&gt;&gt; class Color(Flag): ... RED = auto() ... BLUE = auto() ... GREEN = auto() ... WHITE = RED | BLUE | GREEN </code></pre> <p><strong>Michael #4:</strong> <a href="https://monadical.com/posts/why-use-orm.html#"><strong>Why should you use an ORM (Object Relational Mapper)?</strong></a></p> <ul> <li>You may have heard you should use an ORM, but why?</li> <li>To get a better understanding of how ORMs work, it’s helpful to work through the kind of problems they can solve.</li> <li>Data modeled as classes is great but has some shortcomings <ul> <li>How do you query, filter, sort it?</li> <li>How do you store it? Classes live in memory only and pickling isn’t ideal for many reasons</li> <li>There is also concurrency, transactional operations/atomiticity</li> </ul></li> <li>Enter the DB <ul> <li>But plain SQL is error prone (did you refactor that name? oops)</li> <li>Plain SQL has code written within another language (SQL within Python, tools help but still)</li> <li>Plain SQL has potential security issues (unless you use parameters)</li> </ul></li> <li>ORMs <ul> <li>ORMs are libraries that sit between the SQL database world and your object-oriented programming language world.</li> <li>For all intents and purposes, they are an abstraction layer that allows, among other things, for the translation of Python to SQL.</li> </ul></li> <li>A cycle is formed <ul> <li>Define our models in the Python world as objects</li> <li>the ORM layer translates those models to SQL statements with SQL types to create tables and columns. </li> <li>In our application, we instantiate objects from those models, which creates rows in the aforementioned tables. </li> <li>Finally, when we want those objects back, we use Python code to retrieve them, which triggers the ORM layer to create the necessary query to retrieve the rows from the database. Then, the ORM layer takes the resulting rows and maps them back to objects.</li> </ul></li> <li>And you get migrations</li> </ul> <p><strong>Brian #5:</strong> <a href="https://simonwillison.net/2019/Feb/25/sqlite-utils/"><strong>sqlite-utils: a Python library and CLI tool for building SQLite databases</strong></a></p> <ul> <li>Simon Willison, <a href="https://twitter.com/simonw">@simonw</a></li> <li>“<a href="https://github.com/simonw/sqlite-utils">sqlite-utils</a> is a combination Python library and command-line tool I’ve been building over the past six months which aims to make creating new SQLite databases as quick and easy as possible.”</li> <li>CLI for sqlite <ul> <li>Run queries and output JSON, CSV, or tables</li> <li>analyzing tables</li> <li>inserting data</li> <li>creating, dropping, transforming tables</li> <li>creating indexes</li> <li>searching</li> <li>…</li> </ul></li> <li>Python API for using as a library <ul> <li>way easier interaction with sqlite.</li> </ul></li> </ul> <pre><code> import sqlite_utils db = sqlite_utils.Database("demo_database.db") # This line creates a "dogs" table if one does not already exist: db["dogs"].insert_all([ {"id": 1, "age": 4, "name": "Cleo"}, {"id": 2, "age": 2, "name": "Pancakes"} ], pk="id") </code></pre> <ul> <li><a href="https://sqlite-utils.readthedocs.io/en/stable/">sqlite-utils docs</a></li> </ul> <p><strong>Anthony #6:</strong> <strong>Online conferences are not working for me. But this was a good talk,</strong></p> <ul> <li>“What the struct?!” by Zachary Anglin at the Pyjamas conference.</li> <li>Explains the struct libraries macro-language for converting binary data structures into Python native types (and vice versa) <a href="https://docs.python.org/3/library/struct.html#format-characters">https://docs.python.org/3/library/struct.html#format-characters</a></li> <li>Really nice if you want to programmatically edit/read binary structure (combining with the bitwise operators).</li> <li>If you’re getting into this topic. Save-game hacking is an interesting place to start. </li> <li>I use SynalizeIT! /Synalysis as a binary data grammar explorer. It has some example save game formats <a href="https://www.synalysis.net/formats.xml">https://www.synalysis.net/formats.xml</a></li> <li>Its also great for hacking/CTF.</li> </ul> <p><a href="https://youtu.be/QT_NAk_peHQ?t=7130">https://youtu.be/QT_NAk_peHQ?t=7130</a></p> <p>Extras</p> <p>Brian: </p> <ul> <li>Resurrecting <a href="https://www.meetup.com/Python-PDX-West">Python PDX West</a> as a virtual lunchtime event.</li> <li><a href="https://www.meetup.com/Python-PDX-West/events/275321561/">January is planned for January 14, 2021</a> </li> </ul> <p>Michael:</p> <ul> <li><a href="https://blog.jetbrains.com/pycharm/2020/12/let-s-build-a-fast-modern-python-api-with-fastapi-additional-materials/"><strong>Did a FastAPI webcast</strong></a> people can check out.</li> <li>M1 life is getting better and better</li> </ul> <p>Anthony: </p> <ul> <li>From February 1 I’ll be the new Python Open Source advocate at Microsoft, working with Nina Zacharenko</li> <li>Give us a quick update on Pyjion + .NET Core?</li> </ul> <p>Jokes:</p> <p><a href="https://twitter.com/lk012/status/1334390836172378113">https://twitter.com/lk012/status/1334390836172378113</a></p>

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...