/r/Python
If you have questions or are new to Python use r/LearnPython
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci():
a, b = 0, 1
while True:
yield a
a, b = b, a + b
Online Resources
Five life jackets to throw to the new coder (things to do after getting a handle on python)
PyMotW: Python Module of the Week
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
/r/Python
Introducing our latest Python script: the Facebook Ads Scraper! 🚀
Here's what this powerful tool can do for you:
- **Effortless Page Extraction**: Quickly read Facebook pages from a list of URLs.
- **Comprehensive Ad Scraping**: Process each page URL to extract all ads being run.
- **Deep Ad Insights**: Dive into each ad to scrape details and download associated media.
- **Easy Data Organization**: Neatly organize all scraped data into an Excel document for streamlined analysis.
With our Facebook Ads Scraper, uncovering valuable insights from Facebook ad campaigns has never been easier. Say goodbye to manual data collection and hello to automated efficiency! 💻📊
Don't forget to leave your feedback in the comment section below. Your thoughts help us improve! 👍
Hello everyone,
We are excited to share that after considerable development, our new project is nearing completion. This lightweight Python framework is designed to streamline and accelerate the process of launching your AI applications. Once deployed, your app will be accessible via a public link featuring a chat based user interface.
We are eager to gather your input on this framework. Specifically, we would like to understand the features and capabilities you prioritize when choosing a framework for your projects.
If you are interested in early access, we invite you to join our waitlist for the private beta. You can sign up here: https://cycls.typeform.com/waitlist/
We look forward to your feedback and are keen to incorporate your insights as we refine this tool. Thank you for your interest and support.
While it's unfortunate to have two constructs—TypeGuard and TypeIs—with slightly different behaviors, I'm glad that the latter is less surprising.
Formation debugger is a tool in Formation-studio (a cool drag-n-drop Tkinter GUI designer also made by me) that allows one to hook into running Tkinter applications, inspect the widget hierarchy, and modify properties and layouts all in real-time. It even includes a console allowing you to trigger events, monitor logs and just about anything you can think of doing. To put it simply, it's sort off like Chrome DevTools
but for Tkinter.
I don't think there exists anything else that does this but correct me if I'm wrong.
It comes bundled with Formation Studio so the installation is as simple as
pip install formation-studio
To use it use the command
formation-dbg /path/to/your/tk/app.py
In the embedded python REPL console you can access a simple debugger API as follows:
# Access all widgets currently selected
widgets = debugger.selected
# Access the root widget usually a Tk object
root = debugger.root
It is still a work in progress and may be a little buggy.
Since the debugger has to hook into an arbitrary application without interfering with it, the debugger UI, also written in Tkinter, runs on a separate process. There is therefore tons of IPC to be conducted to get the whole thing working. The code on this is new and may be unclean but still interesting to look at. The code for this tool is under studio/debugtools
in the Formation studio source.
I'm excited to share a project that was initially intended to use in my graduating product(Capstone)
What My Proeject Does
I made NLLB-200 Distill 350M model to translating English to Korean
Target Audience
GPU servers are quite expensive, so I made it for university students who can't cost the server (like me.)
Comparison
It's even smaller and faster the other NLLB-200 model. so it can be run with CPU!
more details are in my page
If you know Korean, please give me a lot of feedback
https://github.com/newfull5/NLLB-200-Distilled-350M-en-ko
thank you!!
Hello /r/Python! It's time to share what you've been working on! Whether it's a work-in-progress, a completed masterpiece, or just a rough idea, let us know what you're up to!
Let's build and grow together! Share your journey and learn from others. Happy coding! 🌟
Pypy has been able to speed up pure python code by a factor of 5 or more for a number of years. The only disadvantage it has is the difficulty in handling C extensions which are very commonly used in practice.
https://peps.python.org/pep-0744 seems to be talking about speed ups of 5-10%. Why are the goals so much more modest than what pypy can already achieve?
archivefile
is a wrapper around tarfile
, zipfile
, py7zr
, and rarfile
.
The above libraries are excellent when you are dealing with a single archive format but things quickly get annoying when you have a bunch of mixed archives such as .zip
, .7z
, .cbr
, .tar.gz
, etc because each library has a slightly different syntax and quirks which you need to deal with.
archivefile
wraps the common methods from the above libraries to provide a unified interface that takes care of said differences under the hood. However, it's not as powerful as the libraries it wraps due to lack of support for features that are unique to a specific archive format and library.
Anyone who's using python to deal with different archive formats
ArchiveFile falls somewhere between the powerful dedicated library and the far less powerful universal libaries.
Repository: https://github.com/Ravencentric/archivefile Docs: https://ravencentric.github.io/archivefile
What My Project Does The Physics Engine Called PhysEng, provides an easy to use environment and visualization combo in which to try out different physics or even provide a template to design your own accelleration/velocity fields. Besides the visualization aspect and numpy the basic functions of the Engine are written completely in 100% python. The features included in the Engine are:
Target Audience PhysEng is made for people who just want to try out different simple simulations or want to design their own physics.
Comparison Looking through github I could never really find a simple and easy-to-use library that did not require me to install some weird libraries or that felt like it was hiding some process from me through using packages. This package is a solution to this since everything is written in python nothing is a secret and can be directed easily.
Get PhysEng There is full documentation available in the Github repo: https://github.com/levi2234/PhysEng
There is no shebang line that actually works across platforms for python 3.
I would like one that works on unmodified :
python
pointing to python2 (PEP 394)cmd.exe
shell (this really just means one that will work with PEP 397)The best work around I have found is:
#!/usr/bin/env python3
python.exe
to python3.exe
python-is-python2
or python-is-python3
is installed, in case you come upon a #!/usr/bin/env python
.As Windows adopts more and more Unix-like behavior, and more distros drop python2, having completely different "portability" rules is going to become a larger problem.
A significant compatibility enhancement would be if the official python packages for Windows just included a python3.exe
to comply with PEP 394. This could be a copy of python.exe
like my workaround, or one could be a minimal executable that just hands off to the other or to py
.
An alternative would be adding py
and pyw
from PEP 397 to PEP 394. and having people move to the shebang #!/usr/bin/env py -3
.
The belt and suspenders compatibility approach is all platforms should have a py
, pyw
, and python3
executable that can launch python3 scripts if requested. And python
should be an executable than runs some version of python.
I am curious what others are using out there? Do others launch python scripts from inside gitbash? do you have a seperate window for running the script and git actions? Are you manually choosing the python executable on the command line?
I've noticed at work that my coworkers and I try out small things in different ways. Small things like if you want to try that adding two datetimes together behaves in the way you expect. Some people use jupyter notebook for this and others run python interactively in a separate command prompt.
I usually run debug in whatever IDE I'm using and then letting it stop at the code I'm currently developing and then using the debug console to test things out. Sometimes this means just leaving the debugger at a breakpoint for half an hour while I continue writing code. Is my way of doing it weird or does it have any disadvantages? How do you usually test out things on the go in a good way?
What My Project Does Shoots is essentially a "data lake" where you can easily store pandas dataframes, and retrieve them later or from different locations or in different tools. Shoots has a client and a server. After choosing a place to run the server, you can easily use the client to "put" and "get" dataframes. Shoots supports SQL, allowing you to put very large dataframes, and then use a query to only get a subset. Shoots also allows you to resample on the server.
# put a dataframe, uploads it to the server
df = pd.read\_csv('sensor\_data.csv')
shoots.put("sensor\_data", dataframe=df, mode=PutMode.REPLACE)
# retrieve the whole data frame
df0 = shoots.get("sensor\_data")
print(df0)
# or use sql to retrieve just some of the data
sql = 'select "Sensor\_1" from sensor\_data where "Sensor\_2" < .2'
df1 = shoots.get("sensor\_data", sql=sql)
Target Audience Shoots is designed to be used in production by data scientists and other python devs using pandas. The server is configurable to run in various settings, including locally on a laptop if desired. It is useful for anyone who wants to share dataframes, or store dataframes so they can be easily accessed from different sources.
Comparison To my knowledge, Shoots is the only data lake with a client that is 100% pandas native. The get() method returns pandas dataframes natively, so there is no cumbersome translations such as required from typical databases and data lakes. The server is build on top of Apache Arrow Flight, and is very efficient with storage because it uses Parquet as the storage format natively. While the Shoots client does all of the heavy listing, if desired, the server can be accessed with any Apache Flight client library, so other languages are supported by the server.
Get Shoots There is full documentation available in the Github repo: https://github.com/rickspencer3/shoots
It is packaged for Pypi as well: (https://pypi.org/project/shoots/) ```pip install shoots"
Hey there,
I'm currently exploring PySpark and attempting to implement Dijkstra's algorithm using it. However, my query doesn't pertain to the algorithm itself; it's regarding the unexpected behavior of the lookup operation in PySpark. To aid in understanding what's happening, I've added print statements and comments throughout the code. This issue seems to be independent of Dijkstra's algorithm, so even if you're not familiar with it, your insights could still be valuable.
Here is my code:
def dijkstra(graph_dict, source_node):
sc = spark.sparkContext
# Initialize distances with infinity for all nodes
distances = sc.parallelize([(node, float('inf')) for node in graph_dict])
# Set the distance of the source node to 0
distances = distances.map(lambda x: (x[0], 0) if x[0] == source_node else x)
print(distances.collectAsMap())
# Initialize priority queue with source node and distance 0
pq = sc.parallelize([(0, source_node)])
while not pq.isEmpty():
# Get the node with minimum distance from the priority queue
current_distance, current_node = pq.min()
print(f'Current Node: {current_node}; Current Distance: {current_distance}')
# Remove the current node from the priority queue
pq = pq.filter(lambda x: x != (current_distance, current_node))
# Iterate over neighbors of the current node
for neighbour, weight in graph_dict[current_node].items():
print(f'neighbour: {neighbour}; weight: {weight}')
# Calculate the distance to the neighbor through the current node
distance = current_distance + weight
print(f'Distance: {distance}')
# Lookup the current distance to the neighbor
lookup_result = distances.lookup(neighbour)[0]
print(f'lookup result for neighbour {neighbour}: {lookup_result}')
# If the new distance is smaller, update the distance and add to priority queue
if distance < lookup_result:
print('True')
distances = distances.map(lambda x: (x[0], distance) if x[0] == neighbour else x)
pq = pq.union(sc.parallelize([(distance, neighbour)]))
return distances.collectAsMap()
The input graph_dict is a python dictionary looks like this:
{'0': {'1': 7, '2': 1, '3': 4},
'1': {'0': 7, '2': 1, '3': 1},
'2': {'0': 1, '1': 1, '3': 10},
'3': {'0': 4, '1': 1, '2': 10}}
Function is called as:
dijkstra(graph_dict, '0')
And this is the output (logs), I am getting when running it:
{'0': 0, '1': inf, '2': inf, '3': inf}
Current Node: 0; Current Distance: 0
neighbour: 1; weight: 7
Distance: 7
lookup result for neighbour 1: inf
True
neighbour: 2; weight: 1
Distance: 1
lookup result for neighbour 2: 1
neighbour: 3; weight: 4
Distance: 4
lookup result for neighbour 3: 4
Current Node: 1; Current Distance: 7
neighbour: 0; weight: 7
Distance: 14
lookup result for neighbour 0: 14
neighbour: 2; weight: 1
Distance: 8
lookup result for neighbour 2: 8
neighbour: 3; weight: 1
Distance: 8
lookup result for neighbour 3: 8
{'0': 0, '1': inf, '2': inf, '3': 8}
From the output, whats weird, is that the lookup result for neighbour 2 should be 'inf' and not 1 and same for all other neighbours. Only for the first time, that is for neighbour 1, its correct as 'inf'.
Excited to share milkcow, my first python package. I'd love any feedback, and to continue to build out the parts of this package that show potential.
https://pypi.org/project/milkcow/ https://github.com/SamReynoso/milkcow
###What MilkCow Does Milkcow automates database creation and offers in-memory key-value mapping for data handling. Whether you're building middleware, local storage, or multiprocessing scripts.
###Target Audience MilkCow is designed for developers looking to streamline the development process. It caters to those who want to simplify data.
###Comparison Milkcow aims for simplicity. Milkcow offers a way for making it easier for developers to get started. Additional functionalities, including database creation and the in-memory datastore, enhancing its usability.
from milkcow import ObjectCow
oc = ObjectCow(Record)
oc.push('Bob', records)
objs = oc.new('Bob')
k, v = oc.items()
for k in oc.keys()
new = oc.new(k)
from milkcow import MilkCow
mc = MilkCow(Record)
mc.pull('Bob')
mc.push('Alice', list[Record])
sender = mc.sender.new_sender()
sender = mc.sender.all_sender()
sender = mc.sender.keyed_sender('Alice')
sender.send()
Hi
I've made a package called mpl_ascii which is a backend for matplotlib. You can find it here: https://github.com/chriscave/mpl_ascii
I would love to share it with others and see what you guys think
What it is
It is a backend for matplotlib that converts your plots into ASCII characters.
At the moment I have only made support for: bar charts, scatter plots and line plots but if there's demand for more then I would love to keep working on it.
Target Audience:
Anyone using matplotlib to create plots who might also want to track how their plots change with their codebase (i.e. version control).
Comparison:
There are a few plotting libraries that produce ASCII plots but I have only come across this one that is a backend for matplotlib: https://github.com/gooofy/drawilleplot. I think it's a great package and it is really clever code but I found it a little lacking when you have multiple colours in a plot. Let me know if you know of other matploblib backends that does similar things.
Use case:
A use case I can think of is for version controlling your plots. Having your plot as a txt format means it can be much easier to see the diff and the files you are committing are much smaller.
Since it is only a backend to matplotlib then you only need to switch to it and you don't need to recreate your plots in a different plotting library.
Thanks for reading and let me know what you think! :)
Hello wonderful community,
Today I'll present to you pyaair, a scraper made pure on Python https://github.com/johnbalvin/pyaair
Easy instalation
` ` `pip install pyaair ` ` `
Easy Usage
` ` ` airports=pyaair.airports("miami","") ` ` `
Always remember, only use selenium, puppeteer, playwright etc when it's strictly necesary
Let me know what you think,
thanks
About me:
I'm full stack developer specialized on web scraping and backend, with 6-7 years of experience
Stumbled upon a useful Python resource? Or are you looking for a guide on a specific topic? Welcome to the Resource Request and Sharing thread!
Share the knowledge, enrich the community. Happy learning! 🌟
Link: https://github.com/Axorax/tkforge
Hey, my name is Axorax. I have been programming for a few years now. I started making a lot more projects in Python recently and this is one of them. I decided to call the project TkForge.
What My Project Does TkForge allows you to turn your Figma design into code. So, you can make the UI for an app in Figma and add input fields, buttons and much more and name them properly then you can run TkForge to convert your Figma design into code. The names need to be the element that you want. For example; if you want a button element then you can name it "button" or "button Hello World!". The "Hello World!" portion will just get ignored. All of the text after the first space is ignored. However, for some elements, they matter. Like, if you want a textbox element with the placeholder text of "Hello" then you need to name it "textbox Hello".
Target Audience It is meant for anyone who wants to create a GUI in Python easily. Dealing with Tkinter can be a pain a lot of times and it also takes a long time. Using TkForge, you can make better UI's and also get a lot of work done in a short amount of time. Anyone who is new to Python or even an expert can use TkForge to speed up their development times and get a better result. You can TkForge in your production app or for a demo app and really anywhere if you are also using Python.
Comparison There is another project called TkDesigner that does the same sort of thing. But TkForge is able to generate better code. TkForge also supports a lot more elements. Placeholder text for textbox and textarea are not built-in to Python. But TkForge has support for those even though using them requires you to handle a lot of situations by yourself (TkForge provides functions for these situations to be handled correctly, you need to implement them were needed yourself).
Thank you for reading! <3
Hey, happy Friday (don't push to prod). Me and some friends are building a no-code platform to run code improvement agents (really in BETA) .
We want to have a quality agent for each language, and I would really appreciate your feedback on python best practices and standards. The agents are created by defining the steps that you want to apply in natural language. Right now our Python agent has the following steps:
In case you want to check our tool, we have a free playground right now at GitGud and are working on github PR integrations.
Happy coding and thank you in advance for your help!
Edit: Of course the steps are really basic right now, we are still testing the POC, so any feedback would be really appreciated
Social media like Reddit, Hacker News, Twitter, etc. contain tons of genuine discussions that you might want to analyze automatically with sentiment analysis. For example you might want to monitor what people say about you, your product, your competitors, etc.
I made a technical article that shows how to implement such a sentiment analysis pipeline using the following steps:
Here it is: https://kwatch.io/how-to-build-a-social-media-sentiment-analysis-pipeline
I hope you will find it useful. If you have some comments about how to improve this pipeline I would love to hear them!
Arthur
I have finished my front-end web dev part. I'm confident in my skills and want to move to the backend section. But the problem is, most influencers promote MERN stack for the backend, and since it's easy to promote as both front end and back end use the same language.
While researching, I found Java, but it's been on a constant decline since 2017, with a 1 percent yearly fall. And languages like Golang and Python are on the rise.
In online debate threads on Reddit, people often mention Python as not scalable and secure, and being very slow. Is that true?
Also, there aren't many Golang courses online.
Welcome to Free Talk Friday on /r/Python! This is the place to discuss the r/Python community (meta discussions), Python news, projects, or anything else Python-related!
Let's keep the conversation going. Happy discussing! 🌟
Sensor-App is an Android App that's main focus is to help create a real-time mobile sensor data stream for computer applications, data collection, AR, VR, etc.
Github: SensorApp
My project is aimed to help provide a Real-Time Mobile Sensor data streaming service.
Computer Programmers, Data Scientists, AR and VR enthusiasts
Thanks for Reading, hope you try out my project :)
Hi y'all,
This might be off topic a bit from the normal stuff that gets posted here, but a while back I was messing around on a Minecraft server that I was hosting on Aternos (a free online Minecraft server host).
Now since the server wasn't running on my computer (and since Aternos has a timeout policy to save server resources) it became annoying for my buddies to hop on the server if I was busy. They'd have to ask me to manually start the server from the webpage.
So I had a free Saturday a couple of months ago and decided to remedy this problem.
My source code is hosted on a GIGO Dev environment if y'all wanna check it out:
https://www.gigo.dev/challenge/1732810200471044096
But to summarize it quickly... I used Playwright and the Discord API in Python to simulate a browser navigating to an Aternos server and starting it. For this tutorial you will need to make an Aternos acct, but their platform is free and very useful if you want to spin up a Minecraft server quickly without using your own resources.
You simply need to configure a trigger command or @ the bot and set up a webhook for the the discord server you want to use.
There's a full tutorial on how I set it up in the link along with the project structure, but truth be told the basic implementation is pretty simple and can be tweaked to work really however you want.
Just wanted to share this to see if anyone had done something similar before, or if I'm just insane and made this mundane problem into a way bigger endeavor than it should be
I want to hear your description of the project you are most proud of. I was just trying to find something on the Internet, but I didn't find much of interest. The only difficult project was CustomTkinter, which, as far as I know, was done entirely in Tkinter. Since it is possible to create something this complex, I'm sure you have something cool too.
Note: I am expecting to hear projects more complex than a calculator :)
Listen at podcast.pythontest.com/219
When starting a SaaS project using Django, there are tons of decisions. I've asked Cory Zue, creator of SaaS Pegasus, to help me sift through some common SaaS/Django decisions.
Hey folks,
I have just posted an article for those who want to go a little bit beyond the basic usage of OTEL and understand how it works under the hood. The post quickly touches on:
- 🔭 History and the idea of OpenTelemetry
- 🧵 Distributed traces & spans. How span collection happens on the service side
- 💼 Baggage & trace ctx propagation
- 📈 Metrics collection. Views & aggregations. Metrics readers
- 📑 OTEL Logging integration
- 🤝 Semantic conventions and why that is important
Blog Post: https://www.romaglushko.com/blog/opentelemetry-sdk/
Let me know what do you think and hope this is helpful for someone 🙌
Version 1.2.0 of UXsim is released, which allows simulating taxis, shared mobility and self-driving taxis!
Main Changes in 1.2.0
UXsim
UXsim is a free, open-source macroscopic and mesoscopic network traffic flow simulator written in Python. It simulates the movements of car travelers and traffic congestion in road networks. It is suitable for simulating large-scale (e.g., city-scale) traffic phenomena. UXsim is especially useful for scientific and educational purposes because of its simple, lightweight, and customizable features, but users are free to use UXsim for any purpose.
Hey everyone,
I’ve recently launched a new website aimed at helping fellow programmers ace their Python interviews. It’s not just limited to Python though; it also covers essential topics like big-O notation, object-oriented programming, design patterns, and more!
I’d love to hear your thoughts and feedback on the content, layout, and anything else you think could be improved.
Check it out here https://hlop3z.github.io/interviews-python/ and let me know what you think. Your input is invaluable in making this resource the best it can be. Thanks in advance for your time and insights! 🚀🐍
Note: It’s mainly to be used in a computer or tablet. You can see it in your mobile, but some sections won’t look as intended.
Welcome to this week's discussion on Python in the professional world! This is your spot to talk about job hunting, career growth, and educational resources in Python. Please note, this thread is not for recruitment.
Let's help each other grow in our careers and education. Happy discussing! 🌟