Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22871

Python Bytes: #285 Where we talk about UIs and Python

$
0
0
<p><strong>Watch the live stream:</strong></p> <a href='https://www.youtube.com/watch?v=XKG_ghz5E7k' style='font-weight: bold;'>Watch on YouTube</a><br> <br> <p><strong>About the show</strong></p> <p>Sponsored: <a href="https://pythonbytes.fm/compiler"><strong>RedHat: Compiler Podcast</strong></a></p> <p>Special guests</p> <ul> <li>Mark Little</li> <li>Ben Cosby</li> </ul> <p><strong>Michael #1:</strong> <a href="https://libgravatar.readthedocs.io/en/latest/"><strong>libgravatar</strong></a></p> <ul> <li>A library that provides a Python 3 interface to the Gravatar APIs.</li> <li>If you have users and want to show <em>some</em> sort of an image, Gravatar is OK</li> <li>PyPI uses this for example (gravatar, not necessarily this lib)</li> </ul> <p>Usage:</p> <pre><code> &gt;&gt;&gt; g = Gravatar('myemailaddress@example.com') &gt;&gt;&gt; g.get_image() 'https://www.gravatar.com/avatar/0bc83cb571cd1c50ba6f3e8a78ef1346' </code></pre> <p><strong>Brian #2:</strong> <a href="https://jsontopydantic.com/"><strong>JSON to Pydantic Converter</strong></a></p> <ul> <li><a href="https://twitter.com/astrochunly/status/1523745834940067840?s=20&amp;t=nJGxm1vQ_4DyIRD5QSHKVg">Suggested by Chun Ly</a>, “this awesome JSON to <a href="https://twitter.com/samuel_colvin">@samuel_colvin</a>'s pydantic is so useful. It literally saved me days of work with a complex nested JSON schema.“</li> <li>“JSON to Pydantic is a tool that lets you convert JSON objects into Pydantic models.”</li> <li>It’s a live site, where you can plop JSON on one the left, and Pydantic models show up on the right.</li> <li>There’s a couple options: <ul> <li>Specify every field as Optional</li> <li>Alias camelCase fields as snake_case</li> </ul></li> <li>It’s also <a href="https://github.com/brokenloop/jsontopydantic">an open source project</a>, built with FastAPI, Create React App, and a project called <a href="https://github.com/koxudaxi/datamodel-code-generator">datamodel-code-generator</a>.</li> </ul> <p><strong>Mark</strong> <strong>#3:</strong> <a href="https://tailwindcss.com/"><strong>tailwindcss</strong></a><strong>,</strong> <a href="https://tailwindui.com/"><strong>tailwindui</strong></a></p> <ul> <li>Not python, but helpful for web UI and open source business model example</li> <li>tailwindcss generates CSS </li> <li>Used on the <strong><a href="https://lexchart.com">Lexchart app</a></strong></li> <li>Benefits of tailwindcss and tailwindui: <ul> <li>Just-in-Time makes it fast. Output includes only classes used for the project.</li> <li>Stand on shoulders of design thinking from <a href="https://www.steveschoger.com/">Steve Schoger</a> and Adam Wathan. See also <a href="https://www.refactoringui.com/">refactoingui.com</a>.</li> <li>Use in current projects without CSS conflicts. <a href="https://www.youtube.com/watch?v=oG6XPy1t1KA">Custom namespace with</a> <a href="https://www.youtube.com/watch?v=oG6XPy1t1KA"><strong>prefix</strong></a> in tailwind.config.js. Bonus: custom namespace prefixes work with the tailwind plug-ins for VS Code and PyCharm.</li> <li>Works well with template engines like, Chameleon. We use tailwind for our app UI. Toolbar template example.</li> <li>Another example of docs and tutorials being a strategic business asset.</li> </ul></li> <li>Resources <ul> <li><a href="https://tailwindcss.com/docs/installation">tailwindcss.com</a></li> <li><a href="https://www.youtube.com/c/TailwindLabs">tailwindlabs</a> on YouTube, great tutorials from Simon at Tailwind</li> <li>Beginner friendly tutorials: <a href="https://www.youtube.com/watch?v=h9Zun41-Ozc&amp;t=1s">Thirus, example of tailwind install methods</a></li> </ul></li> </ul> <p><strong>Michael #4:</strong> <a href="https://peps.python.org/pep-0690/"><strong>PEP 690 – Lazy Imports</strong></a></p> <ul> <li>From Itamar</li> <li>Discussion at https://discuss.python.org/t/pep-690-lazy-imports/15474</li> <li>PEP proposes a feature to transparently defer the execution of imported modules until the moment when an imported object is used.</li> <li>PEP 8 says imports go a the top, that means you pay the full price of importing code</li> <li>This means that importing the main module of a program typically results in an immediate cascade of imports of most or all of the modules that may ever be needed by the program.</li> <li>Lazy imports also mostly eliminate the risk of import cycles or crashes.</li> <li>The implementation in this PEP has already <a href="https://github.com/facebookincubator/cinder/blob/cinder/3.8/CinderDoc/lazy_imports.rst">demonstrated</a> startup time improvements up to 70% and memory-use reductions up to 40% on real-world Python CLIs.</li> </ul> <p><strong>Brian #5:</strong> <strong>Two small items</strong></p> <ul> <li><a href="https://github.com/nicoddemus/pytest-rich"><strong>pytest-rich</strong></a> <ul> <li>Suggested by Brian Skinn</li> <li>Created by Bruno Oliveira as a proof of concept</li> <li>pytest + rich, what’s not to love?</li> <li>Now we just need a maintainer or two or three….</li> </ul></li> <li><a href="https://www.youtube.com/watch?v=8088ORqS3uY">Embedding images in GitHub README</a> <ul> <li>Suggested by Henrik Finsberg</li> <li>Video by Anthony Sottile</li> <li>This is WITHOUT putting the image in the repo.</li> <li>Upload or drop an image to an issue comment. <ul> <li>Don’t save the comment, just wait for GitHub to upload it to their CDN.</li> <li>GH will add a markdown link in the comment text box with a link to the now uploaded image.</li> <li>Now you can use that image in a README file.</li> </ul></li> <li>You can do the same while editing the README in the online editor. </li> </ul></li> </ul> <p><strong>Ben</strong> <strong>#6:</strong> <a href="https://pyauth.github.io/pyotp/"><strong>pyotp</strong></a></p> <ul> <li>A library for generating and verifying one-time passwords (OTP).</li> <li>Helpful for <a href="https://cheatsheetseries.owasp.org/cheatsheets/Multifactor_Authentication_Cheat_Sheet.html">implementing multi-factor authentication (MFA)</a> in web applications.</li> <li>Supports <a href="https://en.wikipedia.org/wiki/HMAC-based_one-time_password">HMAC-based one-time passwords (HOTP)</a> and <a href="https://en.wikipedia.org/wiki/Time-based_one-time_password">time-based one-time passwords (TOTP)</a>. <ul> <li>While HOTP delivered via SMS text messages is a common approach to implementing MFA, <a href="https://cheatsheetseries.owasp.org/cheatsheets/Multifactor_Authentication_Cheat_Sheet.html#sms-messages-and-phone-calls">SMS is not really secure</a>.</li> <li>TOTP using an authenticator app on the user’s device such as Google Authenticator or Microsoft Authenticator is more secure, fairly easy to implement, and free (no SMS messaging fees and multiple free authenticator apps available for users).</li> <li>TOTP works best by making a QR code available to simplify the setup for the user in their authenticator app. Lots of easy to implement QR code generators to choose from (<a href="https://www.npmjs.com/package/qrcode">qrcode</a> is a popular one if you use javascript on the front end).</li> </ul></li> </ul> <p>TOTP quick reference:</p> <pre><code>import pyotp def generate_shared_secret(): # securely store this shared secret with user account data return pyotp.random_base32() def generate_provisioning_uri(secret, email): # generate uri for a QR code from the user's shared secret and email address return pyotp.totp.TOTP(secret).provisioning_uri(name=email, issuer_name='YourApp') def verify_otp(secret, otp): # verify user's one-time password entry with their shared secret totp = pyotp.TOTP(secret) return totp.verify(otp) </code></pre> <p><strong>Extras</strong> </p> <p>Brian:</p> <ul> <li><a href="https://www.youtube.com/watch?v=nWnIRYQrVtk&amp;list=PL2Uw4_HvXqvYeXy8ab7iRHjA-9HiYhRQl"><strong>PyConUS 2022 videos now up</strong></a></li> <li><a href="https://devblogs.microsoft.com/python/python-in-visual-studio-code-may-2022-release/"><strong>A few more Python related extensions for VSCode</strong></a> <ul> <li><a href="https://marketplace.visualstudio.com/items?itemName=ms-python.black-formatter">black</a>, <a href="https://marketplace.visualstudio.com/items?itemName=ms-python.pylint">pylint</a>, <a href="https://marketplace.visualstudio.com/items?itemName=ms-python.isort">isort</a>, and <a href="https://marketplace.visualstudio.com/items?itemName=ms-toolsai.vscode-jupyter-powertoys">Jupyter PowerToys</a></li> </ul></li> <li>Work has begun on a <a href="https://pythontest.com/courses/"><strong>pytest course</strong></a> <ul> <li>Saying this in public to inspire me to finish it.</li> <li>No ETA yet</li> </ul></li> <li><strong><a href="https://anchor.fm/sad-python-girls-club/">Sad Python Girls Club podcast</a></strong></li> </ul> <p>Michael:</p> <ul> <li><a href="https://www.macrumors.com/2022/05/18/pytorch-gpu-accelerated-training-apple-silicon/"><strong>PyTorch M1</strong></a></li> <li><a href="https://missionencodeable.com"><strong>Mission Encodable</strong></a></li> <li><a href="https://github.com/mikeckennedy/pyscript-pwa-example"><strong>PWAs and pyscript</strong></a> <ul> <li>Michael's now released <strong><a href="https://www.youtube.com/watch?v=lC2jUeDKv-s">pyscript PWA YouTube video</a></strong></li> </ul></li> <li><a href="https://cal.com"><strong>cal.com</strong></a> (open source calendly)</li> <li><a href="https://supabase.com"><strong>Supabase</strong></a> (open source Firebase)</li> </ul> <p><strong>Joke:</strong> <a href="https://twitter.com/PR0GRAMMERHUM0R/status/1527725881598287873"><strong>Beginner problems</strong></a></p>

Viewing all articles
Browse latest Browse all 22871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>