Best practices for handling third-party API credentials
Hi,
What are the best practices for handling third-party API credentials in full stack apps?
Example: let's say we're building a SaaS app that uses OpenAI API. The user is expected to provide their own api key (and potentially the base url if they want to use an openai compatible api).
The backend will need these credentials to make calls to the third party api so we will have to send them from the frontend to the backend. We also don't want the user to enter these credentials every time they run an action, so we will have to store them in the database.
What are best practices for handling these credentials? We can't just hash them and store the hash as we need to get the actual key to send it to the 3rd party api. Should we encrypt the key in the backend before storing them in the database? If we do this, where do we store the encryption key? Should it be an environment variable that is provided during runtime (e.g. stored in a password manager in the cloud provider)? But this key needs to be stored permanently, which means we cannot rotate it easily, right?
Also, what about the frontend
/r/Python
https://redd.it/1jdb9fu
Hi,
What are the best practices for handling third-party API credentials in full stack apps?
Example: let's say we're building a SaaS app that uses OpenAI API. The user is expected to provide their own api key (and potentially the base url if they want to use an openai compatible api).
The backend will need these credentials to make calls to the third party api so we will have to send them from the frontend to the backend. We also don't want the user to enter these credentials every time they run an action, so we will have to store them in the database.
What are best practices for handling these credentials? We can't just hash them and store the hash as we need to get the actual key to send it to the 3rd party api. Should we encrypt the key in the backend before storing them in the database? If we do this, where do we store the encryption key? Should it be an environment variable that is provided during runtime (e.g. stored in a password manager in the cloud provider)? But this key needs to be stored permanently, which means we cannot rotate it easily, right?
Also, what about the frontend
/r/Python
https://redd.it/1jdb9fu
Reddit
From the Python community on Reddit
Explore this post and more from the Python community
Is asking for a walk through of a system when arriving in a new company a pipe dream
I have been blessed to have worked at 3 companies but in all 3 i never got a walk through of the system, i would arrive in my department get setup and get told what is done and required from the team ive been assigned too. As a fullstack dev i think it would be cool to get a short walkthrough what the frontend team work with or if im in the front, what the warehouse or backend team works with. Usually i have to figure who to asl and what they do once im assigned something.
So my question is, is it a pipe dream to think someone will give me that kind of deep rundown in my first day or week.
/r/django
https://redd.it/1jdeie6
I have been blessed to have worked at 3 companies but in all 3 i never got a walk through of the system, i would arrive in my department get setup and get told what is done and required from the team ive been assigned too. As a fullstack dev i think it would be cool to get a short walkthrough what the frontend team work with or if im in the front, what the warehouse or backend team works with. Usually i have to figure who to asl and what they do once im assigned something.
So my question is, is it a pipe dream to think someone will give me that kind of deep rundown in my first day or week.
/r/django
https://redd.it/1jdeie6
Reddit
From the django community on Reddit
Explore this post and more from the django community
Astrophysics - Earth's gravitational influence
Hey everyone,
I have a small "space science & astrophysics" Python tutorial series, and the corresponding code is freely available on my GitHub repo (stars are appreciated :-)). My recent "publication" is about the so called Hill-Sphere and Sphere-of-Influence, with our home planet as an example.
What are these concept?
Maybe you have heard in the past about some asteroids that become temporary moons of Earth, or some spacecraft mission that use so-called fly-bys to gain some speed for the outer planets.
In both cases these simple conceptual spheres are used to compute e.g. how stable an orbit is around our home planet.
Why this highly specific example?
Well I am preparing some future videos about these exact topics, so I am currently building up the basics :-). Hope you like it:
Link to the video
GitHub Repo
Cheers,
Thomas
/r/Python
https://redd.it/1jd9vp0
Hey everyone,
I have a small "space science & astrophysics" Python tutorial series, and the corresponding code is freely available on my GitHub repo (stars are appreciated :-)). My recent "publication" is about the so called Hill-Sphere and Sphere-of-Influence, with our home planet as an example.
What are these concept?
Maybe you have heard in the past about some asteroids that become temporary moons of Earth, or some spacecraft mission that use so-called fly-bys to gain some speed for the outer planets.
In both cases these simple conceptual spheres are used to compute e.g. how stable an orbit is around our home planet.
Why this highly specific example?
Well I am preparing some future videos about these exact topics, so I am currently building up the basics :-). Hope you like it:
Link to the video
GitHub Repo
Cheers,
Thomas
/r/Python
https://redd.it/1jd9vp0
GitHub
GitHub - ThomasAlbin/Astroniz-YT-Tutorials: Repository of my Space Science with Python YT tutorial series
Repository of my Space Science with Python YT tutorial series - ThomasAlbin/Astroniz-YT-Tutorials
VJUPYTER DOWNLODE AND RUN IN VISUAL STUDIO COMMUNITY 2022
HOW TO RUN AND INSTALL JUPYTYER IN VISUAL STUDIO COOMUNITY 2022 SAME AS VS CODE?
/r/IPython
https://redd.it/1jdagv6
HOW TO RUN AND INSTALL JUPYTYER IN VISUAL STUDIO COOMUNITY 2022 SAME AS VS CODE?
/r/IPython
https://redd.it/1jdagv6
Reddit
From the IPython community on Reddit
Explore this post and more from the IPython community
ETL completa com Python: Validando Dados e Planilhas de Excel para BI (Projeto end-to-end!)
Olá, pessoal!
Espero que todos estejam bem! Queria compartilhar um vídeo muito legal que pode ajudar a melhorar nossas habilidades em engenharia de dados. O vídeo é "ETL completa com Python: Validando Dados e Planilhas de Excel para BI (Projeto end-to-end!)". Confiram no link abaixo:
https://www.youtube.com/watch?v=JuOyNPjAer8
Aproveitem e bora aprender juntos!
/r/Python
https://redd.it/1jdkn65
Olá, pessoal!
Espero que todos estejam bem! Queria compartilhar um vídeo muito legal que pode ajudar a melhorar nossas habilidades em engenharia de dados. O vídeo é "ETL completa com Python: Validando Dados e Planilhas de Excel para BI (Projeto end-to-end!)". Confiram no link abaixo:
https://www.youtube.com/watch?v=JuOyNPjAer8
Aproveitem e bora aprender juntos!
/r/Python
https://redd.it/1jdkn65
YouTube
Pipeline ETL com Python: Validando Dados e Planilhas de Excel para BI (Projeto end-to-end!)
Faça parte da Jornada! 30% OFF aqui 👇
https://bit.ly/3SB2ohl
GitHub: https://github.com/lvgalvao/etl-python-excel-aovivo
Link dos certificados: https://drive.google.com/drive/folders/1gI5cZmGV5_efqtD_OObSi5DZJguMjOt2?usp=drive_link
► Inscreva-se em nosso…
https://bit.ly/3SB2ohl
GitHub: https://github.com/lvgalvao/etl-python-excel-aovivo
Link dos certificados: https://drive.google.com/drive/folders/1gI5cZmGV5_efqtD_OObSi5DZJguMjOt2?usp=drive_link
► Inscreva-se em nosso…
To GeoDjango or not to GeoDjango
Hello everyone,
I need some insight here. I have an existing Django app using a MySQL database. One of the models that is defined here is called Location. To give you an idea, it just has a name (CharField) and description (TextField), so nothing fancy here.
I have the idea to extend the Location model with actual coordinates. The use case here would be to show where some objects are that have Location as foreign key, using spatial maps and interactive visualizations on the front-end.
I want to extend Location with both a single (x,y) coordinate and a field that defines some sort of bouding box like a polygon. The easiest way would be to use both PointFields and PolygonFields from GeoDjango. I found this implementation to be highly excessive for just the addition of two fields. Also, I'm unsure of changing my database engine django.db.backends.mysql to django.contrib.gis.db.backends.mysql just like that. I can see the benefits of using GeoDjango, but it feels overkill. On the other hand, using plain JSONFields or other fields that represent this data feels like a 'messy' way to solve this issue.
I'm wondering if anyone else has had the same or similar issue? What are your thoughts on this?
Thanks
/r/django
https://redd.it/1jdfzqm
Hello everyone,
I need some insight here. I have an existing Django app using a MySQL database. One of the models that is defined here is called Location. To give you an idea, it just has a name (CharField) and description (TextField), so nothing fancy here.
I have the idea to extend the Location model with actual coordinates. The use case here would be to show where some objects are that have Location as foreign key, using spatial maps and interactive visualizations on the front-end.
I want to extend Location with both a single (x,y) coordinate and a field that defines some sort of bouding box like a polygon. The easiest way would be to use both PointFields and PolygonFields from GeoDjango. I found this implementation to be highly excessive for just the addition of two fields. Also, I'm unsure of changing my database engine django.db.backends.mysql to django.contrib.gis.db.backends.mysql just like that. I can see the benefits of using GeoDjango, but it feels overkill. On the other hand, using plain JSONFields or other fields that represent this data feels like a 'messy' way to solve this issue.
I'm wondering if anyone else has had the same or similar issue? What are your thoughts on this?
Thanks
/r/django
https://redd.it/1jdfzqm
Reddit
From the django community on Reddit
Explore this post and more from the django community
Feedback Wanted: GenAnalyzer - Web App for Protein Sequence Analysis & Mutation Detection
Hello everyone,
I created a web application called GenAnalyzer, which simplifies the analysis of protein sequences, identifies mutations, and explores their potential links to genetic diseases. It integrates data from multiple sources like UniProt for protein sequences and ClinVar for mutation-disease associations.
The application is built using Python Flask for the web framework and Biopython for protein sequence analysis, allowing users to compare sequences and detect mutations.
This project is my graduate project, and I would be really grateful if I could find someone who would use it and provide feedback. Your comments, ratings, and criticism would be greatly appreciated as they’ll help me improve the tool.
You can check out the app here: GenAnalyzer Web App
Feel free to explore the source code and contribute on the GenAnalyzer GitHub Repository
Feel free to leave any feedback, suggestions, or even criticisms. I would be happy for any comments or ratings.
Thanks for your time, and I look forward to hearing your thoughts.
/r/flask
https://redd.it/1jdlp5k
Hello everyone,
I created a web application called GenAnalyzer, which simplifies the analysis of protein sequences, identifies mutations, and explores their potential links to genetic diseases. It integrates data from multiple sources like UniProt for protein sequences and ClinVar for mutation-disease associations.
The application is built using Python Flask for the web framework and Biopython for protein sequence analysis, allowing users to compare sequences and detect mutations.
This project is my graduate project, and I would be really grateful if I could find someone who would use it and provide feedback. Your comments, ratings, and criticism would be greatly appreciated as they’ll help me improve the tool.
You can check out the app here: GenAnalyzer Web App
Feel free to explore the source code and contribute on the GenAnalyzer GitHub Repository
Feel free to leave any feedback, suggestions, or even criticisms. I would be happy for any comments or ratings.
Thanks for your time, and I look forward to hearing your thoughts.
/r/flask
https://redd.it/1jdlp5k
Looking for comments on a background task library I made
https://github.com/ross-sharma/django-task-queue
/r/django
https://redd.it/1jdr11d
https://github.com/ross-sharma/django-task-queue
/r/django
https://redd.it/1jdr11d
GitHub
GitHub - ross-sharma/django-task-queue: A Django app for processing background tasks
A Django app for processing background tasks. Contribute to ross-sharma/django-task-queue development by creating an account on GitHub.
DRF API url location
In Django we typically define our DRF endpoints with a prefix of '/api/'. For a project with multiple DRF apps, where do you define these. Do you define them in the core project folder or do you define each on within it's respective app folder?
/r/django
https://redd.it/1jdj449
In Django we typically define our DRF endpoints with a prefix of '/api/'. For a project with multiple DRF apps, where do you define these. Do you define them in the core project folder or do you define each on within it's respective app folder?
/r/django
https://redd.it/1jdj449
Reddit
From the django community on Reddit
Explore this post and more from the django community
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/1jdrtck
# 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/1jdrtck
Discord
Join the Python Discord Server!
We're a large community focused around the Python programming language. We believe that anyone can learn to code. | 412982 members
[P] I fine-tuned Qwen 2.5 Coder on a single repo and got a 47% improvement in code completion accuracy
Hey all,
Just wanted to share an interesting experiment I ran to see what kind of performance gains can be achieved by fine-tuning a coding model to code from a single repo.
**Tl;dr**: The fine-tuned model achieves a 47% improvement in the code completion task (tab autocomplete). Accuracy goes from 25% to 36% (exact match against ground truth) after a short training run of only 500 iterations on a single RTX 4090 GPU.
https://preview.redd.it/3borsuk1bape1.png?width=1063&format=png&auto=webp&s=8d9510517f3d04163b3ac6b1de6765158886e489
This is interesting because it shows that there are significant gains to be had by fine-tuning to your own code.
**Highlights of the experiment**:
* Model: qwen2.5-coder 14b, 4-bit quantized
* Training data: Svelte source files from this repo: [https://github.com/hcengineering/platform](https://github.com/hcengineering/platform)
* Unsloth for LoRA training with rank 16, 4096 sequence length
* GPU: single RTX 4090
* 500 iterations with effective batch size 8
/r/MachineLearning
https://redd.it/1jdiafd
Hey all,
Just wanted to share an interesting experiment I ran to see what kind of performance gains can be achieved by fine-tuning a coding model to code from a single repo.
**Tl;dr**: The fine-tuned model achieves a 47% improvement in the code completion task (tab autocomplete). Accuracy goes from 25% to 36% (exact match against ground truth) after a short training run of only 500 iterations on a single RTX 4090 GPU.
https://preview.redd.it/3borsuk1bape1.png?width=1063&format=png&auto=webp&s=8d9510517f3d04163b3ac6b1de6765158886e489
This is interesting because it shows that there are significant gains to be had by fine-tuning to your own code.
**Highlights of the experiment**:
* Model: qwen2.5-coder 14b, 4-bit quantized
* Training data: Svelte source files from this repo: [https://github.com/hcengineering/platform](https://github.com/hcengineering/platform)
* Unsloth for LoRA training with rank 16, 4096 sequence length
* GPU: single RTX 4090
* 500 iterations with effective batch size 8
/r/MachineLearning
https://redd.it/1jdiafd
What is the convention for and when it comes to OOP?
Is it a convention in Python that \_ in class method or variable name signifies a private variable, while a _ signifies a protected variable?
I knew it was a convention to use it to signify that a variable or method wasn't to be used outside of the class, but I didn't know about this distinction of private and protected.
For context, I stumbled upon this question when Perplexity AI told me this was the case. I asked it to give me the sources for this but was unable to produce nothing outside a couple of blogs and articles.
So here I am asking the community, what do you think? I think it sounds interesting, to say the least. I have never though about using both __ and _ in the same piece of code, for the sake of consistency (I also thought it was discouraged), but now I am of the opinion that this distinction could actually be useful when designing more complex OOP systems.
/r/Python
https://redd.it/1jdtab6
Is it a convention in Python that \_ in class method or variable name signifies a private variable, while a _ signifies a protected variable?
I knew it was a convention to use it to signify that a variable or method wasn't to be used outside of the class, but I didn't know about this distinction of private and protected.
For context, I stumbled upon this question when Perplexity AI told me this was the case. I asked it to give me the sources for this but was unable to produce nothing outside a couple of blogs and articles.
So here I am asking the community, what do you think? I think it sounds interesting, to say the least. I have never though about using both __ and _ in the same piece of code, for the sake of consistency (I also thought it was discouraged), but now I am of the opinion that this distinction could actually be useful when designing more complex OOP systems.
/r/Python
https://redd.it/1jdtab6
Reddit
From the Python community on Reddit
Explore this post and more from the Python community
I wrote a script to simulate this years March Madness
Here’s the code: https://gist.github.com/CoreyMSchafer/27fcf83e5a0e5a87f415ff19bfdd2a4c
Also made a YouTube walkthrough here: https://youtu.be/4TFQD0ok5Ao
The script uses the inverse of the seeds to weight the teams. There is commented out code that you can adjust to give seeds more/less of an advantage. If you’d like to weight each team individually, you could also add a power attribute to the Team dataclass and at those individually when instantiating the first round.
/r/Python
https://redd.it/1jdsi9u
Here’s the code: https://gist.github.com/CoreyMSchafer/27fcf83e5a0e5a87f415ff19bfdd2a4c
Also made a YouTube walkthrough here: https://youtu.be/4TFQD0ok5Ao
The script uses the inverse of the seeds to weight the teams. There is commented out code that you can adjust to give seeds more/less of an advantage. If you’d like to weight each team individually, you could also add a power attribute to the Team dataclass and at those individually when instantiating the first round.
/r/Python
https://redd.it/1jdsi9u
Gist
March Madness Simulator
March Madness Simulator. GitHub Gist: instantly share code, notes, and snippets.
str2speech: A wrapper for all the new TTS models being released
GitHub: str2speech
# What my project does
Makes it easier to use all the latest TTS models.
I currently support:
- Zyphra Zonos
- Sesame CSM-1B
- Kokoro-82M
- Suno's Bark
- and a few older MMS-TTS models from Facebook
I'll be adding more models soon, like Spark TTS.
# Target Audience
Everyone who's interested in trying out/comparing TTS models. Could be used in production by YouTubers, podcasters, etc. Should work reasonably well in Shell scripts too.
# Comparison
The closest project I can think of is coqui-ai tts. It's a much larger project (supporting xtts, bark, tortoise, and many more models), but it seems to be abandoned. They haven't added support for any models released in the last couple of months.
My project tries to support more modern models. I try to focus on the CLI and ease of use on Google colab.
# Usage
Installation is easy:
And so is usage, I think:
More examples and full code available on GitHub: str2speech
/r/Python
https://redd.it/1jdrvwy
GitHub: str2speech
# What my project does
Makes it easier to use all the latest TTS models.
I currently support:
- Zyphra Zonos
- Sesame CSM-1B
- Kokoro-82M
- Suno's Bark
- and a few older MMS-TTS models from Facebook
I'll be adding more models soon, like Spark TTS.
# Target Audience
Everyone who's interested in trying out/comparing TTS models. Could be used in production by YouTubers, podcasters, etc. Should work reasonably well in Shell scripts too.
# Comparison
The closest project I can think of is coqui-ai tts. It's a much larger project (supporting xtts, bark, tortoise, and many more models), but it seems to be abandoned. They haven't added support for any models released in the last couple of months.
My project tries to support more modern models. I try to focus on the CLI and ease of use on Google colab.
# Usage
Installation is easy:
pip install str2speech
And so is usage, I think:
str2speech --text "Kokoro is nice" --model "kokoro"
More examples and full code available on GitHub: str2speech
/r/Python
https://redd.it/1jdrvwy
GitHub
GitHub - hathibelagal-dev/str2speech: An easy-to-use library and command-line tool for TTS
An easy-to-use library and command-line tool for TTS - hathibelagal-dev/str2speech
Building a Multi-Tenant Automation System in a Django CRM – Seeking Advice
Hi all,
I'm working on a SaaS CRM built with Django/DRF that centers around leads and deals, and I'm looking to implement a robust automation system. The idea is to allow for dynamic, multi-tenant automations that can be triggered by events on leads and deals, as well as scheduled tasks (like daily or weekly operations).
I'm using Django-tenants and django-q2
At a high level, the system should let users set up rules that include triggers, conditions, and actions, with everything stored in the database to avoid hardcoding. I'm considering a design that includes event-driven triggers (using Django signals or an equivalent) and a task queue for longer-running processes, but I'm curious about potential performance pitfalls and best practices when scaling these systems.
I'm interested in hearing from anyone who's built something similar or has experience with automations in a multi-tenant environment. Any advice, pitfalls to watch out for, or suggestions on design and architecture would be greatly appreciated!
Thanks in advance for your help.
/r/django
https://redd.it/1jdzkb8
Hi all,
I'm working on a SaaS CRM built with Django/DRF that centers around leads and deals, and I'm looking to implement a robust automation system. The idea is to allow for dynamic, multi-tenant automations that can be triggered by events on leads and deals, as well as scheduled tasks (like daily or weekly operations).
I'm using Django-tenants and django-q2
At a high level, the system should let users set up rules that include triggers, conditions, and actions, with everything stored in the database to avoid hardcoding. I'm considering a design that includes event-driven triggers (using Django signals or an equivalent) and a task queue for longer-running processes, but I'm curious about potential performance pitfalls and best practices when scaling these systems.
I'm interested in hearing from anyone who's built something similar or has experience with automations in a multi-tenant environment. Any advice, pitfalls to watch out for, or suggestions on design and architecture would be greatly appreciated!
Thanks in advance for your help.
/r/django
https://redd.it/1jdzkb8
Reddit
From the django community on Reddit
Explore this post and more from the django community
Just Built & Deployed a Video Platform MVP ( saketmanolkar.me ) — Looking for Feedback
https://redd.it/1je82un
@pythondaily
https://redd.it/1je82un
@pythondaily
Reddit
From the django community on Reddit: Just Built & Deployed a Video Platform MVP ( saketmanolkar.me ) — Looking for Feedback
Explore this post and more from the django community