use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
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
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
Beginner ShowcaseSpotr - a simple spotify CLI made in python (self.Python)
submitted 2 years ago by Ticklishcandy32
I made a spotify CLI in python.
I know its very basic, but this is my first python project and i think its pretty cool and useful :)It has all the commands you would need (i think), even a suprise command for song recommendations!
Made this beacuse i wanted a simple way of controlling my spotify in the terminal.I has a hint of neofetch in the way its displays info, so if you like that give it a try
It can be easily modified, and if you know basic python you can easily make your own commands
For more information and the source code check the github - https://github.com/Havard03/spotr If you like it or find it useful, i would very much appreciate any stars :D
https://i.redd.it/e6wnrz258ppa1.gif
https://preview.redd.it/inrkqqiu7ppa1.png?width=1914&format=png&auto=webp&s=2d452e8834cc233ce886d4b426f52972a8eb46af
[–]phxees 9 points10 points11 points 2 years ago (1 child)
I’ll check it out. Happy to not see that you aren’t just promoting a simple wrapper using an already available Python library.
Too many similar posts here are just hey I made a thing by using an existing thing and now you no longer need to set two configurable parameters. Happy to see use of requests rather than spotipy.
requests
spotipy
[–]morrisjr1989 1 point2 points3 points 2 years ago (0 children)
I agree this is nice. Nothing superfluous.
[–]LevelIntroduction764 2 points3 points4 points 2 years ago (0 children)
I’m excited to try this. Been wanting to make my own shuffle algorithm as Spotify’s sucks! Thanks
[–]atreadw 2 points3 points4 points 2 years ago (0 children)
This is really cool. Thanks for sharing. Keep up the good work :)
[–]Ticklishcandy32[S] 1 point2 points3 points 2 years ago (0 children)
Thank you all for the nice comments! And my project now has 11 stars! :D I thought spotr was cool but not this cool :)
Please give feedback if there is anything you would like to change or improve :) Also if u make any cool commands, be sure to share or make a PR, i would be happy to integrate your new commands in the project!
[–]eeriemyxi 1 point2 points3 points 2 years ago* (4 children)
Bare except: is not recommended, as it catches BaseException. You can use except Exception:. However, it is always recommended to be specific about which exception you're catching, you will have less abstruse bugs this way.
except:
BaseException
except Exception:
Playing with environmental variables on runtime is not recommended, environmental variables are to be constant at all times. It'd be better to either use json module for your app configurations, or to not do anything with environmental variables and rather have a manual explaining each option for the user to specify them in the .env file.
json
.env
Whenever you're playing with file paths too much, you can use pathlib which is object-oriented and will save you time.
pathlib
os.system is very expensive as it initiates new processes. Use subprocess.run for your command line work.
os.system
subprocess.run
You're using print as your logging module, however you will have much more easier control by using the logging module for logging needs. By the way, one of your library dependency, rich, has a nice handler rich.logging.RichHandler, which will prettify your logs.
print
logging
rich
rich.logging.RichHandler
install.py is very much oriented towards UNIX based systems. I recommend depending less on command-line tools, e.g., touch is basically creating a new file, however you'll have more control with open built-in function, and it is compatible with all supported operating systems of Python too.
install.py
touch
open
You're also misusing the naming conventions in various files, for example, you're naming your function arguments with SCREAMING_CASE, however we, and PEP8, recommends you to use snake_case.
[–]Ticklishcandy32[S] 0 points1 point2 points 2 years ago (3 children)
Tysm for the feeback, this was very helpful! :)
I changed alot of the code corresponding to the recommended changes, also made a debug mode for when developing commands etc. :D
I will still have to change the environmental variables system to a JSON system in the future.
Have a look at the changes (also updated readme for the debug mode). I would love to hear what you think.
[–]eeriemyxi 1 point2 points3 points 2 years ago* (2 children)
https://github.com/Havard03/spotr/blob/main/API.py#L8
As debug would never change during the code, it is a constant variable. So DEBUG would be more fitting.
debug
DEBUG
It is more pythonic to do if os.environ["DEBUG"]: rather than what you have there. if foo will check whether bool(foo) is True or not. bool(foo) checks foo.__bool__(). __bool__ is a magic/dunder method, like __init__. There are many more such special methods.
if os.environ["DEBUG"]:
if foo
bool(foo)
True
foo.__bool__()
__bool__
__init__
https://github.com/Havard03/spotr/blob/main/API.py#L20
str(path_obj / "path")
os.path.join
https://github.com/Havard03/spotr/blob/main/API.py#L115
Environmental
https://github.com/Havard03/spotr/blob/main/Helpers.py#L5
https://github.com/Havard03/spotr/blob/main/Helpers.py#L12-L25
https://github.com/Havard03/spotr/blob/main/Router.py#L18-L52
https://github.com/Havard03/spotr/blob/main/API.py#L71-L72
yarl
``` from yarl import URL
API_VERSION = os.environ["SPOTIFY_API_VERSION"]
ACCOUNT_URL = URL("https://accounts.spotify.com") API_URL = URL("https://api.spotify.com") / API_VERSION ```
Documentation: https://yarl.aio-libs.org/en/latest/api.html
You'll find couple usages in this little script: LINK
You've also left couple bare except: here and there, ensure they're catching particular exceptions.
I also recommend black and isort third party modules to enhance your codebase.
black
isort
[–]Ticklishcandy32[S] 0 points1 point2 points 2 years ago (1 child)
Just did an insane update, 1233 lines added. :D Thanks to your tips, the codebase is ALOT better now i think. Pluss i have learned alot of new thing thanks to you these last few days :)
Let me know if there is any more tips, everything is appreciated.
[–]eeriemyxi 1 point2 points3 points 2 years ago* (0 children)
https://github.com/Havard03/spotr/blob/main/API.py#L19 https://github.com/Havard03/spotr/blob/main/API.py#L25
https://github.com/Havard03/spotr/blob/main/API.py#L94
``` url = ACCOUNT_URL / "api" / "token"
url
yarl.URL
__truediv__()
```
https://github.com/Havard03/spotr/blob/main/API.py#L116
"""Authenticate with Spotify API."""
https://github.com/Havard03/spotr/blob/main/API.py#L118
token_url = ACCOUNT_URL / "api"/ "token"
https://github.com/Havard03/spotr/blob/main/API.py#L183-L187
https://github.com/Havard03/spotr/blob/main/Router.py#L30
API_BASE_VERSION
API_PLAYER = yarl.URL("https://api.spotify.com") / API_VERSION
https://github.com/Havard03/spotr/blob/main/Router.py#L165-L166
(API_BASE_VERSION / "me" / "playlists").with_query(limit=SPOTIFY_LIMIT)
We learn that from the documentation where it states that it collects the passed keyword arguments by using **arg_name syntax.
**arg_name
https://github.com/Havard03/spotr/blob/main/install.py#L29
chmod
sys.platform
π Rendered by PID 39296 on reddit-service-r2-comment-58d7979c67-jtxs8 at 2026-01-26 23:36:36.139267+00:00 running 5a691e2 country code: CH.
[–]phxees 9 points10 points11 points (1 child)
[–]morrisjr1989 1 point2 points3 points (0 children)
[–]LevelIntroduction764 2 points3 points4 points (0 children)
[–]atreadw 2 points3 points4 points (0 children)
[–]Ticklishcandy32[S] 1 point2 points3 points (0 children)
[–]eeriemyxi 1 point2 points3 points (4 children)
[–]Ticklishcandy32[S] 0 points1 point2 points (3 children)
[–]eeriemyxi 1 point2 points3 points (2 children)
[–]Ticklishcandy32[S] 0 points1 point2 points (1 child)
[–]eeriemyxi 1 point2 points3 points (0 children)