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
When I create a new Flask project, here are 15 libraries that are always in my requirements.txt file. What libraries do you use?

I find myself using these libraries in every new Flask project I set up:

* gunicorn
* flask-debugtoolbar
* pytest and pytest-cov
* flake8
* Flask-SQLAlchemy and psycopg2
* alembic
* celery and redis
* Flask-WTF and WTForms-Components
* Flask-Login
* Flask-Limiter
* Flask-Mail

If you want to know why I use all of these libraries, more details can be found at
https://nickjanetakis.com/blog/15-useful-flask-extensions-and-libraries-that-i-use-in-every-project.

What's your favorite extensions and libraries?

/r/flask
https://redd.it/7g4wzg
Sports statistic site

Hi,

I’m a newish full stack developer and I’m trying to build a sports statistic site in Django.

I’m struggling with working out how to structure my project with regards to both the models and the apps I use.

It is a basketball focused application so I’ve started with a player model. There are a ton of stats that each player has for each season so I’ve created a season model that has a player field as a foreignkey. So far so good, I’m struggling to get the data from the API in bulk but that’s another post.

So, we have player and career stats. Now, the next thing I need is team. Teams have all the location and historical stats but then they have players - I think players should reference team as a foreignkey with related name but then I’m not sure how I deal with players when they change team, should there be a former players field and a method to change team that would populate that?

Then we have schedule and match stats. Each game has two teams with a given roster and a given box score that’s not too bad. I need to be more confident in my data collection processes before I’d trust it live.

That’s the main functionality so far. Typing this has helped me clarify my thinking a bit - I’ll stick my work so far up on GitHub at some point if anyone is interested.

If you have initial thoughts, similar projects that might be inspiring and helpful I’d love to hear it.

Hope you’re all doing well!

/r/django
https://redd.it/7gohks
I am after a link to a video of Raymond Hettingers' ...

I lost my bookmarkto a video of Raymond Hettinger's where he discusses best practices when wrapping an external library written in some other language to make it Pythonic. It discusses things like conforming to the Python iterator protocol when the orginal library has just a `get next` function that ends by returning a sentinel value; and other such Pythonicisms.

Your help is appreciated, Thanks :-)


/r/Python
https://redd.it/7gqdni
[R] "Deep Image Prior": deep super-resolution, inpainting, denoising without learning on a dataset and pretrained networks

/r/MachineLearning
https://redd.it/7gls3j
Hi New to flask. Wondering. If my app uses API Keys or connects to a DB whats the most secure way to store these keys/passwords in the app? whats the best practice?



/r/flask
https://redd.it/7gpg5a
Implementing multiple ModelAdmin

In the project I'm working on, I'm using packages like django-import-export, django-summernote, django-polymorphic and I was wondering if there was a way to use their ModelAdmin on the same model at once.

I tried MyModel(SummernoteModelAdmin, PolymorphicModelAdmin) and I got some errors.

Also saw that I could use proxy models to achieve the same results.

Thanks for the help!

/r/djangolearning
https://redd.it/7ginao
[AF] Return streaming text directly into a response, without saving it to disk

I would like to return streaming text directly into a response, without saving it to disk. Right now, I save the streamed data to a file on the server and open that file to return its contents in a response. The following is a little snippet:

class Streamed(Resource):


def post(self):

file = request.files['file']

with open(FOLDER+file.filename, "wb") as f:

while True:

chunk = request.stream.read(CHUNK_SIZE)

if len(chunk) == 0:

return

f.write(chunk)...




/r/flask
https://redd.it/7gtekb
[AF] Peewee question: how to return many rows with just one query?

Hey everyone, I'm using peewee as my ORM in conjunction with Flask. I have this query:

class Group(Model):
name = CharField()

class Project(Model):
name = CharField()
group = ForeignKeyField(Group)

class Scene(Model):
name = CharField()
project = ForeignKeyField(Project)

groups = (Group
.select(Group, Project, Scene)
.join(Project, JOIN_LEFT_OUTER)
.switch(Project)
.join(Scene, JOIN_LEFT_OUTER)
.order_by(Group.order, Project.order, Scene.order)
.aggregate_rows())

What this query does is nest all scenes under the project they have as a foreign key, and nest all projects under the group they have as a foreign key. So I end up with `groups` as a list, `groups[x].projects` as a list, and `groups[x].projects[y].scenes` as a list. I added `aggregate_rows()` at the end because, as far as I can tell from the peewee documentation, this pre-fetches all the data from the query at once.

This query works great for getting & organizing all the data I need but after [printing all queries to stderr](http://docs.peewee-orm.com/en/latest/peewee/database.html#logging-queries) I found that when I marshal `groups` with Flask-RESTful (which serializes all the data to be sent to the client) I end up with 60+ individual queries for every item nested under `groups` (i.e. `projects` and `projects[x].scenes`).

Based on the stderr output it appears that ONLY `Group` is being pre-fetched, while `Project` and `Scene` are not.

My question: **how do I run the above query so it fetches ALL my data at once (without invoking additional queries when being iterated over in Flask-RESTful)?**

Thank you for any help!

/r/flask
https://redd.it/7goeah
When I create a new Flask project, here are 15 libraries that are always in my requirements.txt file. What libraries do you use?

I find myself using these libraries in every new Flask project I set up:

* gunicorn
* flask-debugtoolbar
* pytest and pytest-cov
* flake8
* Flask-SQLAlchemy and psycopg2
* alembic
* celery and redis
* Flask-WTF and WTForms-Components
* Flask-Login
* Flask-Limiter
* Flask-Mail

If you want to know why I use all of these libraries, more details can be found at
https://nickjanetakis.com/blog/15-useful-flask-extensions-and-libraries-that-i-use-in-every-project.

What's your favorite extensions and libraries?

/r/flask
https://redd.it/7g4wzg