Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
3y Django projects without using migrations

I'll need to apply several DB/code changes to a Django project that's at least 3 years old and has never used migrations for the existing models. The database used is SQL Server with SQL Management Studio. All DB changes so far have been made manually. I don't have contact with the initial developers so I don't know the reason why they did not use migrations for any of the apps they built. I do know at some point they migrated from Flask to Django, so that might be the cause.

While it seems like using migrations would be the most efficient way to maintain this project, I'm afraid to break things and make it even more complicated for other engineers touching this code as they are also not familiar with Django and migrations.

Considering how old the project is, would you still advise my team to start implementing migrations after all this time? If so, are there tutorials out there explaining how to do it safely? Please note that the DB names do not follow any of the Django default structure (appname_tablename).

I'm still a beginner in Django and DB management so apologies for any silly questions.

/r/django
https://redd.it/18fzuvh
Advanced Python/Django tutorial that ties together multiple technologies

Hi! Is there an advanced Python tutorial that ties up multiple technologies?

What I mean by "advanced" is that it does not cover just the basics (syntax, loops, data structures), but goes beyond that. You should not be able to follow this tutorial unless you have the basics.

And what I mean by "tieing up multiple technologies" is that I would be interested to see it in the form of a project. A Django web app using Celery and Rabbit MQ running inside a Docker and deployed to AWS EC2. This would encompass Python, Django, Celery, RabbitMQ, Docker, AWS, and some more advanced topics concerning project organization and architecture.

​

Is there such a tutorial, or am I daydreaming and asking for too much?

Cheers! :)

/r/Python
https://redd.it/18fs3i0
flask_security_too fails with LiteSpeed server?

I have a Flask application that uses flask\_security\_too.

When the application is running on Gunicorn, everything is fine. However, on the production environment (public hosting) there's LiteSpeed server. While Gunicorn workers are up all the time, the LiteSpeed process is brought up only if there's a request to be handled, and it is shutdown after a few minutes of inactivity.

With this environment I've observed the following errors in application log:

2023-12-11 16:06:31,291 - CRITICAL: 500 error: Traceback (most recent call last):
File "/home/mydomaindir/virtualenv/domains/site.mydomain.com/3.10/lib/python3.10/site-packages/flask/app.py", line 2190, in wsgi_app response = self.full_dispatch_request()
File "/home/mydomaindir/virtualenv/domains/site.mydomain.com/3.10/lib/python3.10/site-packages/flask/app.py", line 1486, in full_dispatch_request rv = self.handle_user_exception(e)
File "/home/mydomaindir/virtualenv/domains/site.mydomain.com/3.10/lib/python3.10/site-packages/flask/app.py", line 1482, in full_dispatch_request rv = self.preprocess_request()
File "/home/mydomaindir/virtualenv/domains/site.mydomain.com/3.10/lib/python3.10/site-packages/flask/app.py", line 1974, in preprocess_request rv = self.ensure_sync(before_func)()
File "/home/mydomaindir/virtualenv/domains/site.mydomain.com/3.10/lib/python3.10/site-packages/flask_principal.py", line 477, in _on_before_request identity = loader()
File "/home/mydomaindir/virtualenv/domains/site.mydomain.com/3.10/lib/python3.10/site-packages/flask_security/core.py", line 695, in _identity_loader if not isinstance(current_user._get_current_object(), AnonymousUserMixin):
File "/home/mydomaindir/virtualenv/domains/site.mydomain.com/3.10/lib/python3.10/site-packages/werkzeug/local.py", line 515, in _get_current_object return get_name(local()) # type: ignore
File "/home/mydomaindir/virtualenv/domains/site.mydomain.com/3.10/lib/python3.10/site-packages/flask_login/utils.py", line 25, in <lambda> current_user = LocalProxy(lambda: _get_user())
File "/home/mydomaindir/virtualenv/domains/site.mydomain.com/3.10/lib/python3.10/site-packages/flask_login/utils.py", line 372, in

/r/flask
https://redd.it/18fydrc
High school student needs advice on development

Hi, I am developing a website with django, I don't want to get super detailed for ip reasons, but things I have sort of planned but could still change right now:

* I have to extend user model to hold "score" type information for users
* I will be using websockets with django channels for real time interaction between users
* I am using mysql with aws

Obviously there is a lot of work to be done and a lot of details to be hammered out, but I am relatively inexperienced with django as I have only done like two other small somewhat beginner level projects.


I am really just looking for advice. The project that I am working on is really important to me and it does not need to be done any time soon. Is it realistic to expect that I can get this done on my own? Where should I go to look for assistance programming or to find someone else to join? I have been developing for a while, and it seems doable but like it will be a lot of work.

/r/django
https://redd.it/18gapk8
Functions within getcontext()

I'm just working on the last stages of a project where I am building in the ability to capture the visitor IP address, time stamps etc etc (there will be the required privacy/GDPR/Cookie notices) which will be written to a log file.

I have the function to capture IP data, my initial thought was to put this in Middleware but I've tested it by placing it within my get\
context() and it works. Is it good practice to put a function within a class view and call it from within the method, like below, so that the function is called when the page is requested? I initially thought about using some HTMX or JS to call the function from the client. Also, I'm using Wagtail, to be specific, but no difference.

This is the code structure, just wondering if this is OK, before building it out more, obviously I won't be writing to a file in production.

class HomePage(RoutablePageMixin, Page):
foo = ....
bar = ....


/r/djangolearning
https://redd.it/18g92lw
Tuesday Daily Thread: Advanced questions

# Weekly Wednesday Thread: Advanced Questions ๐Ÿ

Dive deep into Python with our Advanced Questions thread! This space is reserved for questions about more advanced Python topics, frameworks, and best practices.

## How it Works:

1. **Ask Away**: Post your advanced Python questions here.
2. **Expert Insights**: Get answers from experienced developers.
3. **Resource Pool**: Share or discover tutorials, articles, and tips.

## Guidelines:

* This thread is for **advanced questions only**. Beginner questions are welcome in our [Daily Beginner Thread](#daily-beginner-thread-link) every Thursday.
* Questions that are not advanced may be removed and redirected to the appropriate thread.

## Recommended Resources:

* If you don't receive a response, consider exploring r/LearnPython or join the [Python Discord Server](https://discord.gg/python) for quicker assistance.

## Example Questions:

1. **How can you implement a custom memory allocator in Python?**
2. **What are the best practices for optimizing Cython code for heavy numerical computations?**
3. **How do you set up a multi-threaded architecture using Python's Global Interpreter Lock (GIL)?**
4. **Can you explain the intricacies of metaclasses and how they influence object-oriented design in Python?**
5. **How would you go about implementing a distributed task queue using Celery and RabbitMQ?**
6. **What are some advanced use-cases for Python's decorators?**
7. **How can you achieve real-time data streaming in Python with WebSockets?**
8. **What are the

/r/Python
https://redd.it/18g8a2m
Introducing UniDep: Unified Conda and Pip Dependency Management

Hello r/python!

I'm excited to share a tool I've been working on called [**UniDep**](https://github.com/basnijholt/unidep) - a tool designed to streamline Python project dependency management by unifying Conda and Pip dependencies in a single `requirements.yaml` file. This approach allows for the creation of a unified Conda `environment.yaml`, while also integrating seamlessly with `setup.py` or `pyproject.toml`.

**Key Features of UniDep:**

- ๐Ÿ”— **Unified Management**: Manage Conda and Pip dependencies together in a single file.
- โš™๏ธ **Project Tool Integration**: Seamless integration with `pyproject.toml` and `setup.py`.
- ๐Ÿข **Monorepo Support**: Merge multiple `requirements.yaml` files into one Conda environment `environment.yaml`.
- ๐ŸŒ **Platform-Specific Support**: Specify dependencies for different operating systems or architectures.
- ๐Ÿ› ๏ธ **Conflict Resolution**: Automated version conflict resolution for complex dependency chains.
- ๐Ÿ”„ **`unidep install` CLI**: A single command to install all Conda, Pip, and local dependencies.
- ๐Ÿ”ง **`pip-compile` Integration**: Generate fully pinned `requirements.txt` files from `requirements.yaml`.

**Getting Started:**

- Installation: Easily install UniDep via pip (`pip install unidep`) or Conda (`conda install -c conda-forge unidep`).
- [GitHub Repo](https://github.com/basnijholt/unidep): Check out the code, examples, and detailed documentation.

**Example:**

```yaml
name: example_environment
channels:
- conda-forge
dependencies:
- numpy # same name on conda and pip
- conda: python-graphviz # When names differ between Conda and Pip
pip: graphviz
-

/r/Python
https://redd.it/18gdt83
Thank you django for getting me through my school project

A little background, my teachers, after not teaching us any html or css or javascript or much of python or any web dev, decided that we should make a simple CRUD website as a projects. Our teacher recommended laravel, which just didn't work for my group. None of us knew php and laravel was so large it was hard to wrap our heads around it.

Eventually I fould django and flask. In the end, we decided to use django because it had enough "batteries-included" that basically everything we needed (logins, simple database, an admin
site) was already there.

And I'm so thankful that the Django docs and tutorials are amazing. I am in love with how django does it's docs. Primarily the tutorial tours most major parts of django, and the "using blank" style articles which gives super beginner friendly advice on how to use things like the user object.

The experience was so good that I actually want to do more web dev stuff after this. Though probably not as a career since I plan on being a teacher (primarily out of spite)

Also our project was ass, it looked like garbage, there was a 6 layer div nest somewhere in the html, the

/r/django
https://redd.it/18gfla3
Adding DRF to my project

I am currently using CRUD for my application using Django. I want to create an API, but unsure how to add it to my project (if that makes sense). Do I just follow the DRF documentation and add a new app to my existing project?

/r/djangolearning
https://redd.it/18gfxjs
Python 3D simulation library

Hi all,

Just wondering if there is any 3d physics simulation library that i can use, im planning to simulate the drainage plane of some structures using some particles, similar to a pool table with balls if the table was inclined in a particular direction.


I have seen pymunk but it looks like it doesnt work with 3d objects..

Thanks in advance
Alwx

/r/Python
https://redd.it/18gggvi
You watched me develop a full SaaS product as a community event. What's next?

Hey r/django,

about a month ago, I made this post. I asked whether you are interested in seeing me create a full SaaS product from idea to production deployment. You were interested! 500 of you joined the various channels.

I loved that response and delivered with a more than 6h long live stream (recording here: https://www.twitch.tv/videos/1973448363). The feedback was great, I didn't hear a single bad word.

But what now? The discord community is fairly active, posting and solving their problems. I love to see that, it's a small dream come true.

However, I want to do something like this again. A big project, maybe multiple streams long. I've also started telling a few business stories on request.

What is something you guys are curious about and would want to see?

/r/django
https://redd.it/18gm8fl
Build a Python music player using libVLC

I wrote a C program that dynamically loads the libvlc shared libraries, exposes some functions to create a player object, load music files, and control playback. I then wrote a Cython wrapper to the C library as a Python extension. Then a jupyter notebook to load and control playback music. The music file can come from local storage, any URL, or even a bytestream in memory that we construct. There isn't a source code posted yet as this is part of a bigger project. In this video I walkthrough the steps to implement a new feature into the player and you will understand how the layers interact.

### Why did I use dlopen and not link at compile time?

So that the module can be built and installed even if VLC is not installed. When it is, the library will use VLC. Also, we might choose to implement a different backend than VLC.

### Why did I not use python-vlc package to implement the application?

The VLC player can be built using the existing python-vlc package. I wanted to showcase the utility of using Cython to call into a C library. You can take this knowledge and apply it to any other C library,

/r/Python
https://redd.it/18gnnl8
Perform Proper Financial Analysis with Python through the Finance Toolkit

A little over 4 months ago I've shared a project that I've been working on for quite some time titled the **Finance Toolkit**. The purpose of this project was to write down as many formulas as used in Finance in the most transparent and simple way to prevent the thing I see so often, the same model, Excel spreadsheet or discussion being done again.

This has led to over 150+ different ratios, technical indicators, performance metrics, risk metrics, economic indicators and more written down in a very simplistic fashion (proof) while letting any kind of data be fed directly into the Toolkit through using the MVC architecture.

See what I mean in the GIF below that demonstrates some of the data that can be obtained. Take a look at the repository here: https://github.com/JerBouma/FinanceToolkit/

https://i.redd.it/w394wqszov5c1.gif

Since this GIF I've made a lot of new improvements which are both technical and finance orientated. First and foremost, I've had multiple requests to improve the speed of data collection. I've therefore experimented with threading to speed up the data collection which you can see gets you financial statements of 345 companies within 40 seconds (and any ratio collection is then done within a couple seconds).

https://preview.redd.it/6vimwe9epv5c1.png?width=2300&format=png&auto=webp&s=bb402b1f8dd07e89c6a1c7f4306118e3021ed220

I've also worked on

/r/Python
https://redd.it/18go3iw
FastStream adds support for Redis

FastStream is a free open-source framework for building asynchronous services interacting with event streams such as **Apache Kafka**, **RabbitMQ**, **NATS** and, since the latest 0.3 release, **Redis**. FastStream simplifies writing producers and consumers for message queues, automatically handling all the parsing, networking and documentation generation. It enables you to write your service once and run it on every streaming protocol with minimal change in setup code.

Please check it out and let us know how to improve it:

https://github.com/airtai/faststream

/r/Python
https://redd.it/18gtrv0
What stack for maintainable frontend rebuild?

Hi,

We built an app between 2018 and today using DRF, Celery (Redis), Postgres, Keycloak for the backend (with a full suite of unittests) and React, Redux, TypeScript for the frontend (with no tests). The React app is also wrapped with React Native to build a mobile app for Android / iOS.

The app is mainly for CRUD operations, the state is not of critical importance (it's not a visual editor or game etc), but we may want to do more with charting libraries in future.

We don't have a significant number of people using our mobile app, they mostly use the web interface.

We don't have a substantial budget.

We've reached a stage where we'd like to rebuild the frontend and want to achieve a few things:

1. Improve the usability and accessibility (to support WCAG 2.2 and possibly Progressive Enhancement (for folks who want to disable JavaScript) of the interface.
2. Build it quickly.
3. Maintain it more easily (ideally with full stack developers rather than deep frontend specialists - this has been a significant challenge: whilst we've had a few backend contributors we've had a great many frontend contributors which has resulted in a bit of a patchwork approach to coding and it is becoming

/r/django
https://redd.it/18gq0st
Getting UserWarning error on Windows Terminal

Has anyone encountered this error before?

c:\python39\lib\site-packages\IPython\core\`completerlib.py:120`: UserWarning: using rootmodules_cache requires you to install the. rootmodules_cache = ip.db.get('rootmodules_cache', {})

I'm on Windows Poweshell terminal and installed the ipython using chocolatey.

/r/IPython
https://redd.it/18gtvxv
Upcoming open community call

Hi r/JupyterNotebooks, u/ericsnekbytes here (from the JupyterLab and Jupyter Notebook councils)

We want to see all the cool things you're doing with Jupyter, so we're holding an open call with the community for people to chat, and share their creations and work. Think of it as a "virtual JupyterCon": It's a place to announce and share fun things happening in the Jupyter community.

**Event Details:**

December 13, 2023, at 9:00AM PST (your [timezone](https://arewemeetingyet.com/Los%20Angeles/2023-12-13/9:00/Jupyter%20Community%20Call))

* Agenda (add yourself) on [HackMD](https://hackmd.io/h_S-qpfsQgS_HFewzJvI5g)
* Meet on [Zoom](https://zoom.us/my/jovyan?pwd=c0JZTHlNdS9Sek9vdzR3aTJ4SzFTQT09)

We meet on Zoom (over video) and:

* Anyone can attend (for free!) ๐Ÿ‘ฉ๐Ÿพโ€๐Ÿš’ ๐Ÿ‘จ๐Ÿผโ€๐Ÿณ ๐Ÿ‘จ๐Ÿฝโ€๐ŸŽค ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿš€ ๐Ÿ‘ฎ๐Ÿปโ€โ™‚๏ธ ๐Ÿ•ต๐Ÿพโ€โ™€๏ธ ๐Ÿ‘จ๐Ÿฟโ€๐Ÿ’ป ๐Ÿ‘ฉ๐Ÿปโ€โš•๏ธ ๐Ÿ‘ฉ๐Ÿผโ€๐ŸŒพ ๐Ÿ‘จ๐Ÿปโ€โš–๏ธ ๐Ÿ‘ฉ๐Ÿฝโ€๐Ÿ”ฌ
* ๐Ÿ–ผ Anyone can present (add yourself the agenda above)
* ๐Ÿ‘€ Anyone can just sit in on the call.
* Presenters will lead a demo and spend a few minutes answering questions
* Topics will be targeted at a broad Jupyter audience (not overly technical)

Watch previous calls from this [YouTube Playlist](https://www.youtube.com/playlist?list=PLUrHeD2K9Cmkoamm4NjLmvXC4Y6E1o8SP).

/r/JupyterNotebooks
https://redd.it/18fwqgo
I made an AI programming assistant that visualizes your code

Here's a video demo!

And try it out here: https://useadrenaline.com/

You can ask general questions or upload a GitHub repository and visualize whatever parts of it you like. I made this since a lot of AI-powered programming assistants are good at answering questions, but not good at visually explaining concepts to you. In terms of how this works, the backend ML logic (finetuning & inference) is written almost entirely in Python.My thinking here is that text alone is not a sufficient interface for navigating large codebases. System diagrams, and visuals more broadly, communicate a lot more about how dependencies, data flow, etc. all work within a repository. And while there are static analysis techniques for visualizing your code, nothing exists right now that leverages LLMs to generate such graphs. The advantage of using language models is in their ability to tailor the complexity of the graph to suit the specific question asked, just like a coworker would do while illustrating a concept on a whiteboard.

Please let me know what y'all think!
And here's the repo on github: https://github.com/shobrook/adrenaline

/r/Python
https://redd.it/18gnamp
D What is the state of Neural ODEs?

Maybe some benchmarks on classification/regression popular tasks. Would be helpful if there is a paper that summarizes the state of neural odes.

I am wondering if i should pursue this field for my Phd. Seems like the field is still growing and there is a lot of research to be done, I am sold by the tagline of "continuous deep models" neural ODEs. But it seems the scale and accuracy of the models are still not great compared to traditional deep models.

I am also looking for a list of professor working in this area.

/r/MachineLearning
https://redd.it/18gv7v1