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
Does django.contrib.auth need a Registration view?

I realize there's a bunch of ways to register users, including using CreateView and FormView (or writing a function based view), but why do the auth views include everything but registration? You would think getting a user signed up and logged in would be something we're all doing every time.

Thoughts?

/r/django
https://redd.it/mbb41i
Recommendations For Using Django DB Sessions With Graphql

Lately I've been learning a modern frontend stack - React and Apollo - and I've been using django-graphene for the graphql implementation.

After reading about the differences between JWT and the default DB based session mechanism which Django uses the latter seems the safest and simplest in many respects. Without graphql, logging in and signing up is easy with the default django forms and views. With graphql, I wasn't sure. In my research for handling authentication with graphql I stumbled upon django-graphql-auth (https://github.com/PedroBern/django-graphql-auth) but it seems to be based on jwt. I cannot seem to find anything else similar which supports the default django session mechanism.

So my question is what is the most painless way for handling authentication for a graphql client using the default django server side session mechanism?

/r/django
https://redd.it/mbdext
Run a long task using threads.

app.py

from flask import Flask, redirect, url_for, render_template
import time
import threading
app = Flask(__name__)


@app.route('/')
def hello():
return render_template('result.html')
def training():
print('training...')
time.sleep(10)
print('training done.')
# return redirect(url_for('done'))
return '<h1> Done </h1>'
@app.route('/done')
def done():
t1= threading.Thread(target=training)
t2 = threading.Thread(target=done)
t1.start()
t2.start()
return '<h1> Working on it... </h1>'
if __name__ == '__main__':
app.run(debug=True)

&#x200B;

result.html

<body>
<a href="{url_for('training')}">Start!</a>
</body>

So I have simulated a long process called 'training'. How do I run training in the background? While it's training in the background I want to return 'working on it...', and after 10 secs I want to display 'done'. I really want to implement threading and not Celery, but if you know the sol using Celery, do let me know. Thank you!

/r/flask
https://redd.it/mbe65e
[P] Release of lightly 1.1.3 - A python library for self-supervised learning

We just released a new version of lightly (https://github.com/lightly-ai/lightly) and after the valuable feedback from this subreddit, we thought some of you might be interested in the updates.

Lightly now supports more models: In addition to SimCLR and MoCo, we have added SimSiam and Barlow Twins (a big thank you to our open-source contributors!). More models, such as BYOL and SwAV are in the pipeline.

We did some benchmarking (https://docs.lightly.ai/getting_started/benchmarks.html) on cifar10 and show the various frameworks in action using different training epochs and batch sizes.
Most models run well on multi-GPU setups using PyTorch Lightning in distributed data-parallel settings.

We are curious to hear your feedback.

/r/MachineLearning
https://redd.it/mbb7cl
starlette-jsonapi now with OpenAPI 3.x support

Disclaimer: I'm the maintainer, trying to make this a bit more visible and gather some feedback.

The latest version of starlette-jsonapi now has "experimental" OpenAPI 3.x (f.k.a. Swagger) support.

GitHub: https://github.com/vladmunteanu/starlette-jsonapi
Documentation: https://starlette-jsonapi.readthedocs.io/en/latest/
Examples: https://github.com/vladmunteanu/starlette-jsonapi/tree/master/examples

/r/Python
https://redd.it/mbc4f9
BlackJack Game!

Hey all! Just learning python, and did a project where I made a fully functional blackjack script! found it quite fun to play so i linked the GitHub link :)if anyone would know how to make it a little bit more compact? if there is anything i can improve just in general feel free :) hope you enjoy!

/r/Python
https://redd.it/mbjdf7
Wednesday Daily Thread: Beginner questions

New to Python and have questions? Use this thread to ask anything about Python, there are no bad questions!

This thread may be fairly low volume in replies, if you don't receive a response we recommend looking at r/LearnPython or joining the Python Discord server at https://discord.gg/python where you stand a better chance of receiving a response.

/r/Python
https://redd.it/mbsiju
DjangoCon Europe 2021 early bird ticket sales are now open!

Hi all!

Early bird ticket sales are now open for DjangoCon Europe 2021! The event will be held entirely online so you can join us from all around the world.

Don’t wait too long to get your ticket because the early bird discount price will end on April 30.

Here is the link to grab your ticket: https://2021.djangocon.eu/about/tickets/

All tickets include access to all 3 conference days (June 2 - 4) and the 2 sprints days (June 5 - 6). Don't forget to follow us on Twitter for the latest up to date information!

/r/django
https://redd.it/mbghtn
Has anyone here used Django with MSSQL? Is it a good idea?

I am interning at a company that is looking to move their back-end CRUD APIs to a Python based framework. We are using on premise MSSQL to fetch the data. I was considering Flask earlier but now I am also looking into Django owing to it's own advantages. Does anyone have experience with Django-MSSQL? Were you able to use connection pooling? Would you suggest it?

/r/django
https://redd.it/mbvzbp
[D] Advanced Takeaways from fast.ai book

I recently read the Fast AI deep learning [book](https://www.goodreads.com/book/show/50204643-deep-learning-for-coders-with-fastai-and-pytorch) and wanted to summarise some of the many advanced takeaways & tricks I got from it. I’m going to leave out the basic things because there’s enough posts about them, i’m just focusing on what I found new or special in the book.

I’ve also put the insights into a [deck](https://saveall.ai/shared/deck/140&4&eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJvd25lciI6NCwiZGVja19pZCI6MTQwfQ.Xd5RK2RLlHjGKoYQET39IqjAZ4JLCkqf119wOjZLjSCdGxwjGxZFWTBbXLvMoHAbhnXOOi6A2bSu3KwGH_S8L5WEn5Cej8kRZ_Bp_XMD_AzFQYM9cR8TvfqSaYQT07HnLkbSCZnM-9OL9rdrzm-hKA2sjLqxOLkDQEqcwCQHiZT0KoweH8Y0nqqKuymWVNUb4A8hyYnORyNXgTaTFbwU2YpEdU43z7PMnPXmr1MtWMe4GQdhCTAfCrsQout8nkHyLE-yUWAFa4jAo-GUAVALgiFr5n0Q7ya5wgA9OWHFwrXYkLSFKzCpw90hpZ_8UYh1dpBCwIIK0CJpOaeIN0ieAg) on save all to help you remember them over the long-term. I would **massively recommend using a spaced repetition app (video** [**explanation**](https://youtu.be/AD0aFdRCskQ)**) like anki or** [**save all**](https://saveall.ai/) **for the things you learn** otherwise you’ll just forget so much of what is important. Here’s the takeaways:

# Neural Network Training Fundamentals

* Always **start** an ML project by **producing simple baselines**
* If is binary classification then could even be as simple as predicting the most common class in the training dataset
* Other baselines: linear regression, random forest, boosting etc…
* Then you can **use your baseline to clean your data** by looking at the datapoints it gets most incorrect and checking to see if they are actually classified correctly in the data
* In general you can also **leverage your baselines** to **help debug** your models


/r/MachineLearning
https://redd.it/mbhewa
Started Learning Python A Week Ago, this is my first python program, any suggestions

So I started learning for a week and got some basic functions down. Inside the program there is a calculator and a few crappy games, can anyone help me improve my code or tell me is my program good?

github:https://github.com/HoHoHoCCH/python1.git

Edit: I am just 10yrs old, so I can make mistakes. If you spot any mistakes, please tell me, thanks!

Edit 2:
NEW UPDATED PROGRAM IS HERE!
Link(GitHub: File name is newprogram1) https://github.com/HoHoHoCCH/python1.git

Enjoy Guys, also if you spot any mistakes or room for improvement. Thanks!

/r/Python
https://redd.it/mc05m5
Python made me look like a WIZARD

Today in work a request comes in for 745 headshots that need to be processed to fit 150x150px for an external platform. One team says it'll take them at least a week to do, the other team says they don't want it as it'll take even longer.

"They need them all black and white! It'll take some time to convert them! They're not even all the same size! UGH this just can't be done in the 2 days they've requested this!!!"

12 lines of code, the Pillow library and exactly 8.856 seconds of running said code... It was done. Panic over. Client happy.

I work in a design team but I'm a job coordinator (so I sort the jobs and make sure the right designers get them). They were amazed it was done so quickly without using Photoshop.

They asked how. I gave them the answer.

Python baby 😎

EDIT

For those wanting to know the code, here it is:

from PIL import Image
import os

for f in os.listdir('Input'):
if f.endswith('.jpg'):
im = Image.new('RGB', (150,

/r/Python
https://redd.it/mca9u2
N Aim 2.2.0 is out! Hugging Face integration and advanced params table management ...

Hi r/MachineLearning community!

Excited to launch Aim v2.2.0 🎉🎉🎉

We are building an open-source self-hosted tool for AI training run comparison. It can handle 1000s of experiments at once and has a simple, straightforward API - super-easy to get started with.

Thanks for the incredible support - helping us democratize AI dev tools.

Check out the new features at play.aimstack.io

Below are a few highlights of this release. Check out the full release post here.

1. HuggingFace Integration

Aim and Hugging Face

2. Metric Visibility Control: hide metrics while they are still in search

Hide individual metrics as well as collectively

3. Column Resize: control your screen real estate for super-long params

Drag column edges back-and-forth to resize

If you haven't yet, drop us a star for support! 🙌

Come say hi at the Aim Slack community.

Check out this version and let us know how we can improve it further 🙏

/r/MachineLearning
https://redd.it/mc8y1f
Jupyter Notebooks in Production

Hi everyone! I'm working with a few people who are developing a way to quickly and easily turn Jupyter Notebooks into hosted apps.

We're trying to get a few people to give us feedback on the software, which we're offering free for a year as a thank you.

Oh, did I mention free compute!?

If you'd be interested in beta testing, let me know via a comment or send me a PM and I'll set it up!

Thanks guys, hope you're all having a great day (:

/r/IPython
https://redd.it/mch0x6
[P] Torchsort - Fast, differentiable sorting and ranking in PyTorch

Introducing Torchsort, an implementation of "Fast Differentiable Sorting and Ranking" [(Blondel et al.)](https://arxiv.org/abs/2002.08871) in PyTorch, complete with a custom C++ and CUDA kernel for fast performance.

pip install torchsort

[https://github.com/teddykoker/torchsort](https://github.com/teddykoker/torchsort)

Differentiable sorting and ranking operations open the door to new loss functions. For example you can easily implement Spearman's rank coefficient using Torchsort, and have a model learn to output predictions with a monotonic relationship to the targets:

import torch
import torchsort

def spearmanr(pred, target, **kw):
pred = torchsort.soft_rank(pred, **kw)
target = torchsort.soft_rank(target, **kw)
pred = pred - pred.mean()
pred = pred / pred.norm()
target = target - target.mean()
target = target / target.norm()
return (pred * target).sum()

pred = torch.tensor([[1., 2., 3., 4., 5.]], requires_grad=True)
target = torch.tensor([[5., 6., 7., 8., 7.]])
spearman

/r/MachineLearning
https://redd.it/mcdoxs
Thursday Daily Thread: Python careers!

Discussion of using Python in a professional environment, getting jobs in Python and more!

This thread is not for recruitment, please see r/PythonJobs or the thread in the sidebar for that.

/r/Python
https://redd.it/mcklyq
How can i setup Token or JWT authentication safely on a Django-Vue app running on the same server?

I'm creating a separated Django-Vue app that should run on the same server but i'm having a very hard time choosing an authentication approach, since i'm not very experienced.

Here are my choices:

1) Since the two apps are on the same domain, use Session authentication: this approach is fine, the problem is that while it would work without troubles in production by simply using Nginx as a reverse proxy, i don't know how to work locally. I'm using Windows and i didn't found a good way to route traffic like i would do with Nginx on linux during production, and also i would have to build static files for my Vue app every time i change something in my code, without being able to use hot reload. Running django and vue on localhost buth on two different ports gave me a nightmare with CSRF cookie settings and sessions. Another big problem is that for some reason i found pretty much nothing on how to authenticate on a Django app using AJAX/Axios instead of standard Django templates. I tried to do that on my own, but instead of receiving an AJAX response i received HTML.

2) Use Token/JWT auth: is this doable? Pretty

/r/django
https://redd.it/mckk4l