Planet Python
Talk Python to Me: #454: Data Pipelines with Dagster
Programiz: Python Program to Capitalize the First Character of a String
Matt Layman: Post-launch Punchlist - Building SaaS with Python and Django #186
Python⇒Speed: The wrong way to speed up your code with Numba
If your NumPy-based code is too slow, you can sometimes use Numba to speed it up. Numba is a compiled language that uses the same syntax as Python, and it compiles at runtime, so it’s very easy to write. And because it re-implements a large part of the NumPy APIs, it can also easily be used with existing NumPy-based code.
However, Numba’s NumPy support can be a trap: it can lead you to missing huge optimization opportunities by sticking to NumPy-style code. So in this article we’ll show an example of:
- The wrong way to use Numba, writing NumPy-style full array transforms.
- The right way to use Numba, namely for loops.
EuroPython: EuroPython 2024: Community Voting is now live! Go Vote!
Hey hey,
With 110 days remaining until the big day, the EuroPython programme team is working full steam ahead to put together a power-packed schedule. And what *YOU* want to see at the conference is our guiding light in the process.
With that, we are excited to announce the EuroPython 2024 Community Voting: https://ep2024.europython.eu/voting 🎉
All past EuroPython attendees between 2015-2024 & prospective speakers from this year are eligible to vote.
You can help us spread the word by forwarding this email to your fellow EuroPython friends.
The more votes we have, the better informed decisions the programme team can make!
Head over to https://ep2024.europython.eu/voting to make your voice heard!
Thank you for your continued support,
EuroPython 2024 Organisers
Python Software Foundation: Announcing a PyPI Support Specialist
We launched the Python Package Index (PyPI) in 2003 and for most of its history a robust and dedicated volunteer community kept it running. Eventually, we put a bit of PSF staff time into the maintenance of the Index, and last year with support from AWS we hired Mike Fiedler to work full-time on PyPI’s urgent security needs.
PyPI has grown enormously in the last 20+ years, and in recent years it has reached a truly massive scale with growth only continuing upward. In 2022 alone, PyPI saw a 57% growth and as of this writing, there are over a half a million packages on PyPI. The impact PyPI has these days is pretty breathtaking. Running a free public service of that size has come with challenges, too. As PyPI has grown, the work of communicating with users and solving account issues here has grown in tandem and out-stripped our current volunteer plus one tenth of a staff person capacity. We also know that some community members have noticed and expressed frustration with the time-frame that goes with tasks that don't have sufficient staffing.
Much of this work is sensitive and complex such that it needs to be performed by a PSF staff person. It involves personal information and verification processes to make sure we’re giving access and names to the correct entities. Work like this needs to be done by a person who is here day after day to carry out multi-step verification procedures and is accountable to the PSF.
We are very happy to share the news that we are hiring a person to help us manage the increased capacity and allow us to keep pace with PyPI’s seemingly unstoppable growth. This is an associate role that is 100% remote. Please take a look at this posting for a PyPI Support Specialist and share it with your networks.
Real Python: Build a Python Turtle Game: Space Invaders Clone
In this tutorial, you’ll use Python’s turtle module to build a Space Invaders clone. The game Space Invaders doesn’t need any introduction. The original game was released in 1978 and is one of the most recognized video games of all time. It undeniably defined its own video game genre. In this tutorial, you’ll create a basic clone of this game.
The turtle module you’ll use to build the game is part of Python’s standard library, and it enables you to draw and move sprites on the screen. The turtle module is not a game-development package, but it gives instructions about creating a turtle game, which will help you understand how video games are built.
In this tutorial, you’ll learn how to:
- Design and build a classic video game
- Use the turtle module to create animated sprites
- Add user interaction in a graphics-based program
- Create a game loop to control each frame of the game
- Use functions to represent key actions in the game
This tutorial is ideal for anyone who is familiar with the core Python topics and wants to use them to build a classic video game from scratch. You don’t need to be familiar with the turtle module to work through this tutorial. You can download the code for each step by clicking on the link below:
Get Your Code: Click here to download the free sample code that shows you how to build a Python turtle game.
In the next section, you can have a look at the version of the game you’ll build as you follow the steps outlined in this tutorial.
Demo: A Python Turtle Space Invaders GameYou’ll build a simplified version of the classic Space Invaders game and control the laser cannon with the keys on your keyboard. You’ll shoot lasers from the cannon by pressing the spacebar, and aliens will appear at regular intervals at the top of the screen and move downwards. Your task is to shoot the aliens before they reach the bottom of the screen. The game ends when one alien reaches the bottom.
This is what your turtle game will look like when you complete this tutorial:
Here you can see the main game play for this game, as the laser cannon moves back and forth and shoots the falling aliens. The game also displays the elapsed time and the number of aliens shot down on the screen.
Project OverviewIn this project, you’ll start by creating the screen that will contain the game. In each step, you’ll create game components such as the laser cannon, lasers, and aliens, and you’ll add the features required to make a functioning game.
To create this turtle game, you’ll work through the following steps:
- Create the game screen and the laser cannon
- Move the cannon left and right using keys
- Shoot lasers with the spacebar
- Create aliens and move them towards the bottom of the screen
- Determine when a laser hits an alien
- End the game when an alien reaches the bottom
- Add a timer and a score
- Improve the cannon’s movement to make the game smoother
- Set the game’s frame rate
You’ll start with a blank screen, and then see the game come to life one feature at a time as you work through each step in this tutorial.
PrerequisitesTo complete this tutorial, you should be comfortable with the following concepts:
- Repeating code using for loops and while loops
- Using if statements to control what happens in different conditions
- Defining functions to encapsulate code
- Using lists to store multiple items
You don’t need to be familiar with Python’s turtle to start this tutorial. However, you can read an overview of the turtle module to find out more about the basics.
If you don’t have all of the prerequisite knowledge before you start, that’s okay! In fact, you might learn more by going ahead and getting started! You can always stop and review the resources linked here if you get stuck.
Step 1: Set Up the Turtle Game With a Screen and a Laser CannonYou can’t have a game without a screen where all the action happens. So, the first step is to create a blank screen. Then, you can add sprites to represent the items in the game. In this project, you can run your code at any point to see the game in its current state.
You can download the code as it’ll look at the end of this step from the folder named source_code_step_1/ in the link below:
Read the full article at https://realpython.com/build-python-turtle-game-space-invaders-clone/ »[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]
Python Morsels: Every dunder method in Python
An explanation of all of Python's 100+ dunder methods and 50+ dunder attributes, including a summary of each one.
Table of contents
- The 3 essential dunder methods 🔑
- Equality and hashability 🟰
- Orderability ⚖️
- Type conversions and string formatting ⚗️
- Context managers 🚪
- Containers and collections 🗃️
- Callability ☎️
- Arithmetic operators ➗
- In-place arithmetic operations ♻️
- Built-in math functions 🧮
- Attribute access 📜
- Metaprogramming 🪄
- Descriptors 🏷️
- Buffers 💾
- Asynchronous operations 🤹
- Construction and finalizing 🏭
- Library-specific dunder methods 🧰
- Dunder attributes 📇
- Every dunder method: a cheat sheet ⭐
There are 3 dunder methods that most classes should have: __init__, __repr__, and __eq__.
Operation Dunder Method Call Returns T(a, b=3) T.__init__(x, a, b=3) None repr(x) x.__repr__() str x == y x.__eq__(y) Typically boolThe __init__ method is the initializer (not to be confused with the constructor), the __repr__ method customizes an object's string representation, and the __eq__ method customizes what it means for objects to be equal to one another.
The __repr__ method is particularly helpful at the the Python REPL and when debugging.
Equality and hashability 🟰In addition to the __eq__ …
Read the full article: https://www.pythonmorsels.com/every-dunder-method/Python Insider: Python 3.10.14, 3.9.19, and 3.8.19 is now available
Howdy!
Those are the boring security releases that aren’t supposed to bring
anything new. But not this time! We do have a bit of news, actually. But
first things first: go update your systems!
Get it here: Python Release Python 3.10.14
26 commits since the last release.Python 3.9.19
Get it here: Python Release Python 3.9.19
26 commits since the last release.
Get it here: Python Release Python 3.8.19
28 commits since the last release.Security content in this release
- gh-115399 & gh-115398: bundled libexpat was updated to 2.6.0 to address CVE-2023-52425, and control of the new reparse deferral functionality was exposed with new APIs. Thanks to Sebastian Pipping, the maintainer of libexpat, who worked with us directly on incorporating those fixes!
- gh-109858: zipfile is now protected from the “quoted-overlap” zipbomb to address CVE-2024-0450. It now raises BadZipFile when attempting to read an entry that overlaps with another entry or central directory
- gh-91133: tempfile.TemporaryDirectory cleanup no longer dereferences symlinks when working around file system permission errors to address CVE-2023-6597
- gh-115197: urllib.request no longer resolves the hostname before checking it against the system’s proxy bypass list on macOS and Windows
- gh-81194: a crash in socket.if_indextoname() with a specific value (UINT_MAX) was fixed. Relatedly, an integer overflow in socket.if_indextoname() on 64-bit non-Windows platforms was fixed
- gh-113659: .pth files with names starting with a dot or containing the hidden file attribute are now skipped
- gh-102388: iso2022_jp_3 and iso2022_jp_2004 codecs no longer read out of bounds
- gh-114572: ssl.SSLContext.cert_store_stats() and ssl.SSLContext.get_ca_certs() now correctly lock access to the certificate store, when the ssl.SSLContext is shared across multiple threads
Upgrading is highly recommended to all users of affected versions.
Source builds are moving to GitHub ActionsIt’s not something you will notice when downloading, but 3.10.14 here is the first release we’ve done where the source artifacts were built on GHA and not on a local computer of one of the release managers. We have the Security Developer in Residence @sethmlarson to thank for that!
It’s a big deal since public builds allow for easier auditing and repeatability. It also helps with the so-called bus factor. In fact, to test this out, this build of 3.10.14 was triggered by me and not Pablo, who would usually release Python 3.10.
The artifacts are later still signed by the respective release manager, ensuring integrity when put on the downloads server.
Python now manages its own CVEsThe security releases you’re looking at are the first after the PSF became a CVE Numbering Authority. That’s also thanks to @sethmlarson. What being our own CNA allows us is to ensure the quality of the vulnerability reports is high, and that the severity estimates are accurate. Seth summarized it best in his announcement here.
What this also allows us to do is to combine announcement of CVEs with the release of patched versions of Python. This is in fact the case with two of the CVEs listed above (CVE-2023-6597 and CVE-2024-0450). And since Seth is now traveling, this announcement duty was fulfilled by the PSF’s Director of Infrastructure @EWDurbin. Thanks!
I’m happy to see us successfully testing bus factor resilience on multiple fronts with this round of releases.
Thank you for your supportThanks to all of the many volunteers who help make Python Development and these releases possible! Please consider supporting our efforts by volunteering yourself or through organization contributions to the Python Software Foundation.
Python.org - the official home of the Python Programming Language.–
Łukasz Langa @ambv
on behalf of your friendly release team,
Ned Deily @nad
Steve Dower @steve.dower
Pablo Galindo Salgado @pablogsal
Łukasz Langa @ambv
Thomas Wouters @thomas
PyCoder’s Weekly: Issue #621 (March 19, 2024)
#621 – MARCH 19, 2024
View in Browser »
In this tutorial, you’ll learn how to use the Python seaborn library to produce statistical data analysis plots to allow you to better visualize your data. You’ll learn how to use both its traditional classic interface and more modern objects interface.
REAL PYTHON
Depending on how you’re using the term “pointer” changes the answer to the question. Read on to better understand the programming terminology and whether Python has pointers.
NED BATCHELDER
GPT Pilot is a collection of AI agents that automate developer workflows to try offloading 95% of coding tasks from you to the AI. Right now, it can build apps up to ~3000 lines of code see examples here →
PYTHAGORA TECHNOLOGIES INC. sponsor
This article introduces you to how Python stores things in memory. Learn about the heap, the stack, and how the interpreter sees Python objects.
PEPIJN BAKKER
Large language models (LLMs) have taken the world by storm, demonstrating unprecedented capabilities in natural language tasks. In this step-by-step tutorial, you’ll leverage LLMs to build your own retrieval-augmented generation (RAG) chatbot using synthetic data with LangChain and Neo4j.
REAL PYTHON
Sometimes adding code in one place means configuration elsewhere also needs to be updated. One way of ensuring this is happening properly in a large project is to use unit tests. This post covers a few examples, complete with pytest code.
JUSTIN DUKE
Code reviews are great - but they shouldn’t slow down your development. Sourcery can automatically review every one of your PR’s so your team can keep moving fast →
SOURCERY sponsor
The pickle module allows you to serialize arbitrary Python objects. Serializing them back means executing code, which has potential security issues. Read on to discover what they are and what software may be impacted.
DAROC ALDEN
In this Python Basics Exercises video course, you’ll practice installing packages with pip. You’ll also practice creating virtual environments, making lists of requirements, and recreating a development environment.
REAL PYTHON course
Accessing a database in a terminal is not the best solution for everyone. Mljar lets you build a dashboard from scratch using only Python.
MLJAR • Shared by Piotr
Regular expression syntax is only somewhat uniform across programming languages. Seth ran into a surprise with “$” and Python.
SETH LARSON
An opinion piece on feature flags and the dangers of letting PMs control them. Includes suggestions on what to do instead.
ANTON ZAIDES
Learn how “The 2038 problem” could impact software, hardware, and more - and what can be done to prepare.
CODE RELIANT
This is a step-by-step guide to adding email sign-in (and verification) to Django using Gmail and others.
PHOTON DESIGNER
This post dives deep into Python’s smtpd module and explores how it can used for local testing.
MUHAMMAD
March 20, 2024
REALPYTHON.COM
March 21, 2024
MEETUP.COM
March 21, 2024
PYLADIES.COM
March 23 to March 25, 2024
BARCAMPS.EU
March 23, 2024
MEETUP.COM
Happy Pythoning!
This was PyCoder’s Weekly Issue #621.
View in Browser »
[ Subscribe to 🐍 PyCoder’s Weekly 💌 – Get the best Python news, articles, and tutorials delivered to your inbox once a week >> Click here to learn more ]
Real Python: SQLite and SQLAlchemy in Python: Move Your Data Beyond Flat Files
All programs process data in one form or another, and many need to be able to save and retrieve that data from one invocation to the next. Python, SQLite, and SQLAlchemy give your programs database functionality, allowing you to store data in a single file without the need for a database server.
You can achieve similar results using flat files in any number of formats, including CSV, JSON, XML, and even custom formats. Flat files are often human-readable text files—though they can also be binary data—with a structure that can be parsed by a computer program. You’ll explore using SQL databases and flat files for data storage and manipulation and learn how to decide which approach is right for your program.
In this video course, you’ll learn how to use:
- Flat files for data storage
- SQL to improve access to persistent data
- SQLite for data storage
- SQLAlchemy to work with data as Python objects
[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]
Robin Wilson: One reason for getting a ‘No HTTP triggers found’ error when using Azure Functions with Python V2 programming model
Summary: It might be because there is an exception raised when importing your function_app.py – for example, caused by one of your import statements raising an exception, or a parsing error caused by a syntax error.
I was deploying a FastAPI app to Azure Functions recently. Azure Function is the equivalent of AWS Lambda – it provides a way to run serverless functions.
Since I’d last used Azure Functions, Microsoft have introduced the Azure Functions Python V2 programming model which makes it easier and cleaner to do a number of common tasks, such as hooking up a FastAPI app to run on Functions.
However, it also led to an error that I hadn’t seen before, and that I couldn’t find documented very well online.
Specifically, I was getting an error at the end of my function deployment saying No HTTP triggers found. I was confused by this because I had followed the documented pattern for setting up a FastAPI app. For reference, my function_app.py file looked a bit like this:
import azure.functions as func from complex_fastapi_app import app app = func.AsgiFunctionApp(app=app, http_auth_level=func.AuthLevel.ANONYMOUS)This was exactly as documented. But I kept getting this error – why?
I replaced the import of my complex_fastapi_app with a basic FastAPI app defined in function_app.py, this time copied directly from the documentation:
import azure.functions as func from fastapi import FastAPI, Request, Response fast_app = FastAPI() @fast_app.get("/return_http_no_body") async def return_http_no_body(): return Response(content="", media_type="text/plain") app = func.AsgiFunctionApp(app=fast_app, http_auth_level=func.AuthLevel.ANONYMOUS)Everything worked fine now and I didn’t get the error.
After a lot of debugging, it turns out that if there is an exception raised when importing your function_app.py file then Functions won’t be able to establish what HTTP triggers you have, and will give this error.
In this case, I was getting an exception raised when I imported my complex_fastapi_app, and that stopped the whole file being processed. Unfortunately I couldn’t find anywhere that this error was actually being reported to me – I must admit that I find Azure logging/error reporting systems very opaque. I assume it would have been reported somewhere – if anyone reading this can point me to the right place then that’d be great!
I’m sure there are many other reasons that this error can occur, but this was one that I hadn’t found documented online – so hopefully this can be useful to someone.
The Python Coding Blog: The Python Coding Book is Out in Paperback and EBook
The Python Coding Book is out—I published the First Edition in paperback and EBook, which is a revised version of the “Zeroth” Edition which you’ve been able to read here on this site for a while—just ask Google for a “python book” and it will recommend this one as one of it’s top entries!
Read on to see the table of contents, the back-cover blurb introducing the textbook, and testimonials from you, the readers!
Buy Paperback or EBookThe Python Coding Book • A relaxed and friendly programming textbook for beginners
Table of ContentsFirst Edition, 368 pages
- 0 Preface • How to Learn to Code
- Before You Start • Downloading Python and an IDE
- 1 Getting Started: Your First Project
- 2 Loops, Lists, and More Fundamentals
- 3 Power-up Your Coding: Create Your Own Functions
- 4 Data, Data Types, and Data Structures
- Monty and The White Room: Understanding Programming
- 5 Dealing With Errors and Bugs
- 6 Functions Revisited
- 7 Object-Oriented Programming
Imagine a programming book that feels like a conversation with a friend who’s here to show you the ropes—that’s The Python Coding Book by Stephen Gruppetta. This isn’t a dry textbook. It’s a warm, engaging guide into the world of Python programming, designed with beginners in mind.
With an approach that emphasises clarity and the joy of learning, Stephen guides you through the core concepts of programming, breaking down the barriers that make coding seem inaccessible to many. This book is built on the premise that to truly grasp programming, you need to understand the ‘why’ just as much as the ‘how’. Through engaging explanations, thoughtful analogies, and practical projects, you’re not just learning to code—you’re learning to think and solve problems like a programmer.
Forget about overwhelming details and rapid leaps in complexity. The Python Coding Book introduces concepts at a pace that ensures comprehension, building a solid foundation that instils both knowledge and confidence.
Are you ready for a rewarding journey? The Python Coding Book is more than a book—it’s your first step towards mastering programming with Python. This book is an invitation to not only learn Python but to fall in love with coding.
Testimonials“It’s the first time I’m understanding what everything does.”
“Your writing is succinct, easy to understand, and process oriented, which I really appreciate. I’m starting to realise that my first experiences with programming weren’t at all representative of my abilities to problem solve or structure my thinking. It has been a great confidence booster for me, and I’m sure other folks are also realising that they were never really the problem. It was the lack of resources or inaccessible information that was the issue. Thanks again for this wonderful resource.”
“The clarity of your writing has helped me understand Python at a deeper level.”
“Thank you for this great resource. I believe this book is the most comprehensive way to understand the material, going beyond the mere memorisation of code snippets or syntax. I recommend it to everyone I talk to who is looking for a Python resource for getting started and who wants to really understand what they are doing at a deeper level.”
Buy Paperback or EBookThe post The Python Coding Book is Out in Paperback and EBook appeared first on The Python Coding Book.
Python Bytes: #375 Pointing at Countries
Hynek Schlawack: You Can Build Portable Binaries of Python Applications
Contrary to popular belief, it’s possible to ship portable executables of Python applications without sending your users to Python packaging hell.
Data School: Jupyter & IPython terminology explained 💡
Are you trying to understand the differences between Jupyter Notebook, JupyterLab, IPython, Colab, and other related terms? You&aposre in the right place!
I&aposll explain by walking through a brief history of the IPython and Jupyter projects:
- IPython (2006)
- IPython Notebook (2011)
- Jupyter Notebook (2015)
- JupyterLab (2018)
- Summary (present day)
IPython was first released in 2006 as an "interactive" version of the Python shell. Whereas the Python shell uses the >>> prompt, you can recognize IPython from its use of In [1] and Out [1] notation to indicate input/output and line numbers:
IPython includes many features not present in the default Python shell, such as object introspection, "magic" commands, system shell access, and more.
IPython NotebookIn 2011, the IPython Notebook was released. It was known as a "computational notebook" because it allowed you to weave together code, plots, and narrative text into a single document:
It was called the IPython Notebook (and not the Python Notebook) because it used IPython as the "kernel", which is the language-specific process that runs the code in a notebook.
Jupyter NotebookIn 2015, the IPython Notebook introduced support for programming languages other than Python.
Also in 2015, IPython split into two projects: IPython (for Python-specific components) and Jupyter (for language-agnostic components).
As part of that split, the IPython Notebook was renamed the Jupyter Notebook. The name "Jupyter" was inspired by the open languages of science: Julia, Python, and R:
To be clear, "Jupyter Notebook" was the name of both the coding environment and the files created by that environment. In other words, you would open "the Jupyter Notebook" to create "a Jupyter notebook".
Jupyter notebook files used the extension ".ipynb", which was the extension (and file format) originally created for IPython notebooks.
JupyterLabAt this point, the Jupyter Notebook was a lightweight coding environment, with far less features than a traditional IDE (integrated development environment).
In 2018, JupyterLab (one word) was released as a more full-featured alternative to the Jupyter Notebook:
Notebooks created within JupyterLab are still called "Jupyter notebooks", they still use the extension ".ipynb", and they&aposre compatible with notebooks created by the Jupyter Notebook.
JupyterLab was originally designed to replace the Jupyter Notebook environment. However, due to the continued popularity of the "classic" Notebook environment, JupyterLab and Jupyter Notebook continue to be developed as separate applications (as of 2024).
Summary- The Jupyter Notebook is a lightweight coding environment for creating and editing Jupyter notebooks.
- JupyterLab is more full-featured IDE for creating and editing Jupyter notebooks.
- IPython is the Python kernel for Jupyter Notebook and JupyterLab, and is also a standalone Python shell. IPython is the reason that magic commands and other enhancements are available within Jupyter Notebook and JupyterLab.
- Jupyter notebooks are computational documents that can contain code, plots, and text. They use the extension ".ipynb" and are compatible with both the Jupyter Notebook and JupyterLab environments.
Here are a few related terms that I didn&apost mention above:
- JupyterLab Desktop is a cross-platform desktop application that allows you to create and manage multiple JupyterLab sessions and Python environments.
- JupyterLite is a JupyterLab distribution that runs entirely in the browser, without you having to launch a Jupyter server from a terminal.
- Google Colab, Kaggle Code, and Deepnote are a few of the many web-based services that provide a Jupyter-like interface for creating notebooks that are compatible with Jupyter. (More specifically, they can import and export files that use the ".ipynb" format.)
Are there any other Jupyter-related terms you want me to explain? Please let me know if the comments! 👇
Real Python: Model-View-Controller (MVC) in Python Web Apps: Explained With Lego
If you’re curious about web development, then you’ve likely encountered the abbreviation MVC, which stands for Model-View-Controller. You may know that it’s a common design pattern that’s fundamental to many Python web frameworks and even desktop applications.
But what exactly does it mean? If you’ve had a hard time wrapping your head around the concept, then keep on reading.
In this tutorial, you’ll:
- Approach understanding the MVC pattern through a Lego-based analogy
- Learn what models, views, and controllers are conceptually
- Tie your conceptual understanding back to concrete web development examples
- Investigate Flask code snippets to drive the point home
Maybe you built things with Lego as a kid, or maybe you’re still a Lego-aficionado today. But even if you’ve never pieced two Lego blocks together, keep on reading because the analogy might still be a good building block for your understanding.
Get Your Code: Click here to download an example Flask app that will help you understand MVC in Python web apps.
Take the Quiz: Test your knowledge with our interactive “Model-View-Controller (MVC) in Python Web Apps: Explained With Lego” quiz. Upon completion you will receive a score so you can track your learning progress over time:
Explaining the Model-View-Controller Pattern With LegoImagine that you’re ten years old and sitting on your family room floor. In front of you is a big bucket of Lego, or similar modular building blocks. There are blocks of all different shapes and sizes:
- 🟦🟦🟦 Some are blue, tall, and long.
- 🟥 Some are red and cube-shaped.
- 🟨🟨 Some are yellow, big, and wide.
With all of these different Lego pieces, there’s no telling what you could build!
Just as your mind is filling with the endless possibilities, you hear something coming from the direction of the couch. It’s your older brother, voicing a specific request. He’s saying, “Hey! Build me a spaceship!”
“Alright,” you think, “that could actually be pretty cool.” A spaceship it is!
So you get to work. You start pulling out the Lego blocks that you think you’re going to need. Some big, some small. Different colors for the outside of the spaceship, different colors for the engines.
Now that you have all of your building blocks in place, it’s time to assemble the spaceship. And after a few hours of hard work, you now have in front of you—a spaceship:
🟦 🟦🟥🟦 🟦🟥🟥🟥🟦 🟦🟥🟥🟥🟥🟥🟦 🟦🟥🟥🟥🟥🟥🟦 🟦🟥🟩🟩🟩🟥🟦 🟦🟥🟩🟦🟩🟥🟦 🟦🟥🟩🟩🟩🟥🟦 🟦🟥🟥🟥🟥🟥🟦 🟦🟥🟥🟥🟥🟥🟦 🟦🟥🟥🟥🟥🟥🟦 🟦🟥🟥🟥🟥🟥🟥🟥🟥🟥🟦 🟦🟥🟥🟥🟥🟥🟥🟥🟥🟥🟦 🟦🟥🟨🟨🟥🟥🟥🟨🟨🟥🟦 🟨🟨 🟨🟨You run to find your brother and show him the finished product. “Wow, nice work!”, he says. Then he quietly adds:
Huh, I just asked for that a few hours ago, I didn’t have to do a thing, and here it is. I wish everything was that easy.
— Your Brother
What if I told you that building a web application using the MVC pattern is exactly like building something with Lego blocks?
User Sends a Request Read the full article at https://realpython.com/lego-model-view-controller-python/ »[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]
ListenData: Python for Data Science: Beginner's Guide
This tutorial would help you to learn Data Science with Python by examples. It is designed for beginners who want to get started with Data Science in Python. Python is an open source language and it is widely used as a high-level programming language for general-purpose programming. It has gained high popularity in data science world. In the PyPL Popularity of Programming language index, Python leads with a 29 percent share. In advanced analytics and predictive analytics market, it is ranked among top 3 programming languages for advanced analytics.
Data Science with Python Tutorial Table of Contents Introduction Python is widely used and very popular for a variety of software engineering tasks such as website development, cloud-architecture, back-end etc. It is equally popular in data science world. In advanced analytics world, there has been several debates on R vs. Python. There are some areas such as number of libraries for statistical analysis, where R wins over Python but Python is catching up very fast.With popularity of big data and data science, Python has become first programming language of data scientists.There are several reasons to learn Python. Some of them are as follows -
- Python runs well in automating various steps of a predictive model.
- Python has awesome robust libraries for machine learning, natural language processing, deep learning, big data and artificial Intelligence.
- Python wins over R when it comes to deploying machine learning models in production.
- It can be easily integrated with big data frameworks such as Spark and Hadoop.
- Python has a great online community support.
- YouTube
- Dropbox
- Disqus
- Download Anaconda. It comes with Python software along with preinstalled popular libraries.
- Download Pythonfrom its official website. You have to manually install libraries.
- Jupyter (Ipython) Notebook
- Spyder
To read this article in full, please click hereThis post appeared first on ListenData
ListenData: 15 Free Open Source ChatGPT Alternatives (with Code)
In this article we will explain how Open Source ChatGPT alternatives work and how you can use them to build your own ChatGPT clone for free. By the end of this article you will have a good understanding of these models and will be able to compare and use them.
Benefits of Open Source ChatGPT AlternativesThere are various benefits of using open source large language models which are alternatives to ChatGPT. Some of them are listed below.
- Data Privacy: Many companies want to have control over data. It is important for them as they don't want any third-party to have access to their data.
- Customization: It allows developers to train large language models with their own data and some filtering on some topics if they want to apply
- Affordability: Open source GPT models let you to train sophisticated large language models without worrying about expensive hardware.
- Democratizing AI: It opens room for further research which can be used for solving real-world problems.
Llama stands for Large Language Model Meta AI. It includes a range of model sizes from 7 billion to 65 billion parameters. Meta AI researchers focused on scaling the model's performance by increasing the volume of training data, rather than the number of parameters. They claimed the 13 billion parameter model outperformed 175 billion parameters of GPT-3 model. It uses the transformer architecture and was trained on 1.4 trillion tokens extracted by web scraping Wikipedia, GitHub, Stack Exchange, Books from Project Gutenberg, scientific papers on ArXiv.
Python Code : Llama # Install Package pip install llama-cpp-python from llama_cpp import Llama llm = Llama(model_path="./models/7B/ggml-model.bin") output = llm("Q: Name the planets in the solar system? A: ", max_tokens=128, stop=["Q:", "\n"], echo=True) print(output) In the model path, you need to have weights for Llama in GGML format and then store them into the models folder. You can search it on Hugging Face website. See one of them here Llama 2 What's New in Llama 2Here are some of the key differences between Llama 2 and Llama:
- Training data: Llama 2 is trained on 40% more tokens than Llama, a total of 2 trillion tokens. This gives it a larger knowledge base and allows it to generate more accurate responses.
- Model size: Llama 2 is available in three sizes: 7 billion parameters, 13 billion parameters, and 70 billion parameters. Whereas, the maximum size of Llama is 65 billion parameters.
- Chat optimization: Llama 2-Chat is a specialized version of Llama 2 that is optimized for engaging in two-way conversations. It has been trained on a dataset of human conversations, which allows it to generate more natural and engaging responses.
- Safety and bias mitigation: Llama 2 has been trained with a focus on safety and bias mitigation. This means that it is less likely to generate toxic or harmful content.
- Open source: Llama 2 is open source, which means that anyone can use it for research or commercial purposes. Whereas, Llama can't be used for commercial purposes.
To run Llama2 7B model, refer the code below. The following code uses a 4-bit quantization technique that reduces the size of the LLM, which can make it easier to deploy and use on sytems with limited memory.
Colab: Llama2 7B Model %cd /content !apt-get -y install -qq aria2 !git clone -b v1.3 https://github.com/camenduru/text-generation-webui %cd /content/text-generation-webui !pip install -r requirements.txt !pip install -U gradio==3.28.3 !mkdir /content/text-generation-webui/repositories %cd /content/text-generation-webui/repositories !git clone -b v1.2 https://github.com/camenduru/GPTQ-for-LLaMa.git %cd GPTQ-for-LLaMa !python setup_cuda.py install !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/4bit/Llama-2-7b-Chat-GPTQ/raw/main/config.json -d /content/text-generation-webui/models/Llama-2-7b-Chat-GPTQ -o config.json !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/4bit/Llama-2-7b-Chat-GPTQ/raw/main/generation_config.json -d /content/text-generation-webui/models/Llama-2-7b-Chat-GPTQ -o generation_config.json !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/4bit/Llama-2-7b-Chat-GPTQ/raw/main/special_tokens_map.json -d /content/text-generation-webui/models/Llama-2-7b-Chat-GPTQ -o special_tokens_map.json !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/4bit/Llama-2-7b-Chat-GPTQ/resolve/main/tokenizer.model -d /content/text-generation-webui/models/Llama-2-7b-Chat-GPTQ -o tokenizer.model !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/4bit/Llama-2-7b-Chat-GPTQ/raw/main/tokenizer_config.json -d /content/text-generation-webui/models/Llama-2-7b-Chat-GPTQ -o tokenizer_config.json !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/4bit/Llama-2-7b-Chat-GPTQ/resolve/main/gptq_model-4bit-128g.safetensors -d /content/text-generation-webui/models/Llama-2-7b-Chat-GPTQ -o gptq_model-4bit-128g.safetensors %cd /content/text-generation-webui !python server.py --share --chat --wbits 4 --groupsize 128 --model_type llama Llam2: 13 Billion ParametersTo run Llama2 13B model, refer the code below.
Colab: Llama2 13B Model %cd /content !apt-get -y install -qq aria2 !git clone -b v1.8 https://github.com/camenduru/text-generation-webui %cd /content/text-generation-webui !pip install -r requirements.txt !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/4bit/Llama-2-13b-chat-hf/resolve/main/model-00001-of-00003.safetensors -d /content/text-generation-webui/models/Llama-2-13b-chat-hf -o model-00001-of-00003.safetensors !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/4bit/Llama-2-13b-chat-hf/resolve/main/model-00002-of-00003.safetensors -d /content/text-generation-webui/models/Llama-2-13b-chat-hf -o model-00002-of-00003.safetensors !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/4bit/Llama-2-13b-chat-hf/resolve/main/model-00003-of-00003.safetensors -d /content/text-generation-webui/models/Llama-2-13b-chat-hf -o model-00003-of-00003.safetensors !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/4bit/Llama-2-13b-chat-hf/raw/main/model.safetensors.index.json -d /content/text-generation-webui/models/Llama-2-13b-chat-hf -o model.safetensors.index.json !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/4bit/Llama-2-13b-chat-hf/raw/main/special_tokens_map.json -d /content/text-generation-webui/models/Llama-2-13b-chat-hf -o special_tokens_map.json !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/4bit/Llama-2-13b-chat-hf/resolve/main/tokenizer.model -d /content/text-generation-webui/models/Llama-2-13b-chat-hf -o tokenizer.model !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/4bit/Llama-2-13b-chat-hf/raw/main/tokenizer_config.json -d /content/text-generation-webui/models/Llama-2-13b-chat-hf -o tokenizer_config.json !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/4bit/Llama-2-13b-chat-hf/raw/main/config.json -d /content/text-generation-webui/models/Llama-2-13b-chat-hf -o config.json !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/4bit/Llama-2-13b-chat-hf/raw/main/generation_config.json -d /content/text-generation-webui/models/Llama-2-13b-chat-hf -o generation_config.json %cd /content/text-generation-webui !python server.py --share --chat --load-in-8bit --model /content/text-generation-webui/models/Llama-2-13b-chat-hf Alpaca Introduction : AlpacaA team of researchers from Stanford University developed an open-source language model called Alpaca. It is based on Meta's large-scale language model Llama. The team used OpenAI's GPT API (text-davinci-003) to fine tune the Llama 7 billion (7B) parameters sized model. The goal of the team is to make AI available for everyone for free so that academicians can do further research without worrying about expensive hardwares to execute these memory-intensive algorithms. Although these open source models are not available for commercial use, small businesses can still utilize it for building their own chatbots.
How does Alpaca workThe Stanford team began their research with the smallest language model among Llama models, which was the Llama 7B model, and pre-trained it with 1 trillion tokens. They started with the 175 human-written instruction-output pairs from the self-instruct seed set. They then used OpenAI API to ask ChatGPT to generate more instructions using the seed set. It is to obtain roughly 52,000 sample conversations, which the team used to further fine-tune the Llama models using Hugging Face's training framework.
To read this article in full, please click hereThis post appeared first on ListenDataBrett Cannon: State of WASI support for CPython: March 2024
The biggest update since June 2023 is WASI is now a tier 2 platform for CPython! This means that the main branch of CPython should never be broken more than 24 hours for WASI and that a release will be blocked if WASI support is broken. This only applies to Python 3.13 and later, although I have been trying to keep Python 3.11 and 3.12 working with WASI as well.
To help make this support easier, the devguide has build instructions for WASI. There is also now a WASI step in CI to help make things easier for core developers.
Starting in wasmtime 14, a new command line interface was introduced. All the relevant bits of code that call wasmtime have been updated to use the new CLI in Python 3.11, 3.12, and 3.13/main.
Lastly, 3.13/main and 3.12 now support WASI SDK 21 – which is the official name of the project – and 3.11 is one bug fix away in the test suite from also having support.
At this point I think CPython has caught up to what&aposs available in WASI 0.2 and wasi-libc via WASI SDK. The open issues are mostly feature requests or checking if assumptions related to what&aposs supported still hold.
I&aposm on parental leave at this point, so future WASI work from me is on hold until I return to work in June. Another side effect of me becoming a parent soon is I stepped down as the sponsor of Emscripten support in CPython. That means CPython 3.13 does not officially support Emscripten and probably starting in 3.14, I will be removing any code that complicates supporting WASI. The Pyodide project already knows about this and they don&apost expect it to be a major hindrance for them since they are already used to patching CPython source code.