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
[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
I'm a newbie programmer looking for advice on managing my Python installation and also which Terminal style UI library to use.

I'm pretty new to Python and programming in general. I'm ready to start building bigger projects with richer UIs than just the console output. I quite liked the idea of doing everything in an old school terminal style and Googled around a bit. I found a thing called Curses. But also NCurses and NPyScreen. I want to make simple games and applications for my own use but am happy with ASCII art for now.

I also am using Python as installed via Anaconda (and using the Spyder editor). I'm getting really confused about how to install things like NCurses. It actually appears in Anaconda and is installed but now I don't know where to find any documentation about it. I wouldn't know how to install NPyScreen (it doesn't appear in Anaconda).

Any help would be greatly appreciated. Maybe I should be using something else to manage my Python installation - but Anaconda was the only way I could get Python and PyGame installed successfully! Thanks.

/r/Python
https://redd.it/7gxwpm
Help with kivy on PyCharm?

Ok, so first of all please realize that I'm pretty new to Python, and generally programming as a whole. As in, got serious about it less than a week ago. But I've already gotten pretty proficient at the basics. Just a warning that if you don't accurately explain what you're saying, I probably won't get it.

ANYWAYS

I'm trying to get kivy to work on PyCharm and its not going too hot. I also had problems when trying to install Django, but I realized you need PyCharm pro to use that anyways, so I decided I didn't care enough for that. However, upon doing more research and found that kivy would probably work for a lot of things I'd like to try.

So, I installed kivy and started watching a few tutorial videos to try it out. But then whenever I attempted to run my code it just didn't work.

Here's what happens when I run it:

C:\Users\Owner\PycharmProjects\ktest\venv\Scripts\python.exe

C:/Users/Owner/.PyCharmCE2017.3/config/scratches/kivytut.py

[INFO ] [Logger ] Record log in C:\Users\Owner\.kivy\logs\kivy_17-12-01_76.txt

[INFO ] [Kivy ] v1.10.0

[INFO ] [Python ] v3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)]

[INFO ] [Factory ] 194 symbols loaded

[INFO ] [Image ] Providers: img_tex, img_dds, img_gif (img_sdl2, img_pil, img_ffpyplayer ignored)

[CRITICAL] [Window ] Unable to find any valuable Window provider.

sdl2 - ImportError: DLL load failed: The specified module could not be found.
File "C:\Users\Owner\PycharmProjects\ktest\venv\lib\site-packages\kivy\core\__init__.py", line 59, in core_select_lib
fromlist=[modulename], level=0)
File "C:\Users\Owner\PycharmProjects\ktest\venv\lib\site-packages\kivy\core\window\window_sdl2.py", line 26, in <module>
from kivy.core.window._window_sdl2 import _WindowSDL2Storage

[CRITICAL] [App ] Unable to get a Window, abort.

Process finished with exit code 1

So, yeah, that's a big lovely mess. My best guess is that I did something wrong when installing it? It seems like I set it up in PyCharm correctly, so I really don't think thats the problem, but I could be wrong. If I'm right and I didn't install something correctly, how would I fix that?

Some help would be lovely, thanks!

oh yeah, and I'm on windows btw!

/r/Python
https://redd.it/7h0blg
Getting into JS and REST, but: Could I django-channels everything?

Hello everyone.

Preface: I'm a hobbyist and I am not subject to any restrictions. I don't need to be concerned about backwards compatiblity, special tooling that might not be 100% production ready, browser compatibility, hirability, other developers that need to understand my code, etc...

Having mentioned that, let's continue: I'm somewhat decent with Django now, but thus far I only worked with Django templates. I am currently learning JS and Vue as well as starting to get into the DRF. I want to be using the "simplest" (meaning straight to the point, as little tooling, as little other libraries and plugins as possible) yet most up-to-date way possible.

So I also looked into Django channels. I tried looking into it enough so that I can answer my own question, but I don't seem to have understood this well enough to do so: Couldn't I just use Django-channels for everything?

1. As far as I understood I could simply send my JSON data through websockets instead of through the DRF. Is that correct? And if it is, why is nobody doing it? What am I overseeing? Could I completely replace DRF by django-channels? Is there any good technical reason why I shouldn't do this?

2. The same should be valid for AJAX. I know some NodeJS people use websockets instead of AJAX, but I never read about this anywhere else. Why is nobody doing this? Or do I just not notice it because I am not in the professional webdev scene? Maybe someone with enough technical knowledge could say a few words about this?

Thanks a lot in advance! Sorry if this is a ridiculous question.



/r/django
https://redd.it/7gut63
Looking for advice on demonstrating knowledge to future employers

Hi all,

Was just laid off my first engineering job after three years. While I'm confident in my abilities, I need a good way to show future employers my abilities. Right now, my GitHub has a few shitty projects from University and that's it. (I'm five classes away from my bachelor's, only one is CS related.) My work with my now former employer is inaccessible and proprietary, so off the table for use.

What might be the best thing to do to give employers an idea of my abilities? Thanks!

/r/Python
https://redd.it/7h103f
Using django for realtor site

Do you think django could be a good bet for a realtor site? (I dont want to use Wordpress)
I just want to do the typical things: listing houses, manage agents, forms for request house's information.

Ps. I have experience making websites with Laravel.

Thanks!

/r/django
https://redd.it/7gyx7u
How to assign new user their profile link? www.site.com/userid, or userid.site.com

I am trying to figure out what is the best way to assign a new profile link

* 1. www.site.com/userid
* 2. userid.site.com

Which one is preferable keeping in mind user accessibility, SEO, and website complexity.


/r/django
https://redd.it/7h24jg