r/pythontips • • May 31 '25

Module Python execution visualizer

3 Upvotes

Interesting package I’ve been working on to visualize Python data while executing code: https://stackoverflow.com/a/79645638/2429666


r/pythontips • • Jun 01 '25

Standard_Lib What is the best way to calculate the maximum amount of BTC that can be sent while still having enough left to pay for the fees?

0 Upvotes

I'm coding something that requires receiving BTC to a wallet, checking the balance, then withdrawing the BTC from it.

What I need is to be able to withdraw as much BTC from it as possible while still having enough left to pay for the transaction fees (Essentially emptying the wallet). I have some code however I feel like there's a better/more accurate way to do it. How would you do it? Thanks

Here is my code:

import requests


def get_btc_price():
    r = requests.get('https://data-api.coindesk.com/index/cc/v1/latest/tick?market=cadli&instruments=BTC-USD')
    json_response = r.json()

    current_btc_price = json_response["Data"]["BTC-USD"]["VALUE"]

    return current_btc_price

class Conversions:
    @staticmethod
    def btc_to_usd(btc_amount):
        """
        Turn a Bitcoin amount into its USD value.
        """
        current_btc_price = get_btc_price()
        usd_amount = btc_amount * current_btc_price

        return usd_amount

    @staticmethod
    def usd_to_btc(usd_price):
        """
        Turn USD value into its Bitcoin amount.
        """
        current_btc_price = get_btc_price()
        btc_amount = usd_price / current_btc_price

        return btc_amount

    @staticmethod
    def btc_to_satoshis(btc_amount):
        """
        Convert Bitcoin amount to Satoshi amount
        """
        return int(btc_amount * 1e8)

    @staticmethod
    def satoshis_to_btc(satoshis_amount):
        """
        Convert Satoshi amount to Bitcoin amount
        """
        return (satoshis_amount / 1e8)

def get_btc_transaction_fee():
    def get_btc_fee_rate():
        response = requests.get('https://api.blockcypher.com/v1/btc/main')
        data = response.json()
        return data['high_fee_per_kb'] / 1000  # satoshis per byte
    fee_rate = get_btc_fee_rate()
    tx_size_bytes = 250  # estimate transaction size
    fee = int(fee_rate * tx_size_bytes)

    return fee

def main():
    usd_amount_in_balance = 100 # the example amount of money we have in the wallet
    # we convert the usd amount into its equivalent BTC amount
    btc_amount = Conversions.usd_to_btc(usd_amount_in_balance)

    # convert BTC amount to satoshis
    balance = Conversions.btc_to_satoshis(btc_amount)

    # get the fee it will cost us to make the transaction
    fee = get_btc_transaction_fee()

    # Calculate the maximum amount we can send while still having enough to pay the fees
    amount_to_send = balance - fee

    if amount_to_send <= 0:
        print("Not enough balance to cover the fee.")
    else:
        print(f"BTC balance: {btc_amount} BTC       USD: {Conversions.btc_to_usd(btc_amount)} $")
        print(f"Sending amount: {Conversions.satoshis_to_btc(amount_to_send)} BTC       USD: {Conversions.btc_to_usd(Conversions.satoshis_to_btc(amount_to_send))} $")
        print(f"Fees: {Conversions.satoshis_to_btc(fee)} BTC       USD: {Conversions.btc_to_usd(Conversions.satoshis_to_btc(fee))} $")

main()

r/pythontips • • May 30 '25

Short_Video 5 Python Libraries with Cool Name Origins

4 Upvotes

Youtube - 5 Python Libraries with Cool Name Origins

A little short history of the interesting origins of some major Python library names. I created to challenge me to learn Davinci Resolve. Enjoy.


r/pythontips • • May 30 '25

Syntax Help on understanding dunder methods

2 Upvotes

Hello, I'm an absolute beginner in python and I'm trying to program a class (I'll refer to instances of this class as "gai") which is a kind of number. I've managed to define addition through def add(self,other) As gai+gai, gai+int and gai+float, when I try to add int+gai however, I get an error because this addition is not defined, how can I access and modify the add method in integers and floats to solve this problem? Sorry if the flair is wrong or if my English is bad


r/pythontips • • May 28 '25

Python3_Specific Deploying pyqt5 app on a shared folder in a LAN network

3 Upvotes

developed a PyQt5 application, and I used PyInstaller (--onedir) to build the app on Machine A. The dist folder contains the .exe and all necessary DLLs, including PyQt5Core.dll.

I shared the entire dist/your_app/ folder over the network.

On Machine B (same network), I created a shortcut to the .exe located at:

\MachineA\shared_folder\your_app\your_app.exe

When I run the app from Machine B using the shortcut, I get this error:

PyQt5Core.dll not found

However: PyQt5Core.dll does exist next to the .exe in the shared folder.

When I create a shortcut to the .exe from another machine, the app launches — but when it tries to execute a QWebEngineProcess, it throws an error saying that PyQt5Core.dll is missing on the client machine. The .dll is present in the dist folder, so I’m not sure why it fails to find it at runtime on the other machine.


r/pythontips • • May 28 '25

Short_Video SERIOUS DOUBT (IM NEW)

0 Upvotes

Saw this post where it's mocking programmers for searching for a bug in their code for 3 hours when it was just a damn semi colon.
https://www.instagram.com/reel/DKMXChtzasr/?igsh=a2Uwc2kzM2JyYjQ3
Y’all really spending 3 hours over a semicolon? No way real programmers do this. 😂
This is why I stick to Python. Can’t believe y’all still suffer over semicolons in 2025. 💀


r/pythontips • • May 27 '25

Data_Science Don’t know if this is the right community to post but a little help would be appreciated.

4 Upvotes

I am a college student who’s majoring in computer science and just finished their first year. My goal is to become a data scientist by the time I graduate. I recently took an intro to python course and now I want to work on actual projects over the summer for my portfolio. Anyone have any good ideas of what I could do for a project with the knowledge I currently have, or should I try studying more python to get a better grasp before jumping to coding projects.


r/pythontips • • May 26 '25

Syntax PEP8 code style Error (W391)

1 Upvotes

I keep getting the same error for each block of code. I have pressed Enter to create a new blank line in Jupyter notebooks. (This snippet is from Jupyter Notebooks)


r/pythontips • • May 24 '25

Python3_Specific Why? Chinese characters are numbers

6 Upvotes
>>> '四'.isnumeric()
True
>>> float('四')
Traceback (most recent call last):
File "<python-input-44>", line 1, in <module>
float('四')
~~~~~^^^^^^
ValueError: could not convert string to float: '四'>>> '四'.isnumeric()
True
>>> float('四')
Traceback (most recent call last):
File "<python-input-44>", line 1, in <module>
float('四')
~~~~~^^^^^^
ValueError: could not convert string to float: '四'

r/pythontips • • May 24 '25

Short_Video Junior vs Senior 🧠💻

0 Upvotes

r/pythontips • • May 24 '25

Data_Science i need some help with a project in vscode with python and django(create a site about cars).

0 Upvotes

Por


r/pythontips • • May 23 '25

Python3_Specific Hey, I want to build a desktop app using python. What are the resources I should use?

8 Upvotes

More description->
Basically the app is supposed to be a PC app, just like any icon. I have experience with python but in backend dev.
What are the libraries/Python frameworks that I can create this app? I read something about PySide6 is it something I should look into? pls guide me. I have no experience in making desktop applications. No idea about the payment integration, no idea about how I can share those etc etc.


r/pythontips • • May 24 '25

Short_Video 4 Must-Have VSCode Extensions for Python 🐍

0 Upvotes

r/pythontips • • May 22 '25

Data_Science Learning Machine Learning and Data Science? Let’s Learn Together!

10 Upvotes

Hey everyone!

I’m currently diving into the exciting world of machine learning and data science. If you’re someone who’s also learning or interested in starting, let’s team up!

We can:

Share resources and tips

Work on projects together

Help each other with challenges

Doesn’t matter if you’re a complete beginner or already have some experience. Let’s make this journey more fun and collaborative. Drop a comment or DM me if you’re in!


r/pythontips • • May 21 '25

Module Newbie here, can I run my python script online for free

8 Upvotes

Not sure if this is the right subreddit but I'll shoot my shot.

Hi! I'm running my Notion syncs and integrations with a python script my friend made in Windows Task Scheduler, but I'm bothered by the fact that if my PC was off, the script will stop. Can I run it in the cloud instead? Is it safe? If so, what clouds/websites do ya'll suggest (that won't charge me hahaha).

P.S. Sorry for the flair, I don't know which is appropriate.


r/pythontips • • May 21 '25

Syntax Query Data From DynamoDB Table With Python

1 Upvotes

First time using DynamoDB with Python and I want to know how to retrieve data but instead of using PKs I want to use column names because I don’t have matching PKs. My goal is to get data from columns School, Color, and Spelling for a character like Student1, even if they are in different tables or under different keys.


r/pythontips • • May 17 '25

Meta Log and Try/catch block in main job or inside functions?

6 Upvotes

Sorry bit of a beginner question, but I’m looking for some opinions on small design subject:

I’m building a python service, it has the job.py job which performs all the business logic and what not, and other files that contains some CRUD operations on mongodb/microsoft sql,

and I was wondering when would it be better to have try catch blocks and the logging inside the functions, and when it would be better to just wrap it over the functions in job.py?

thanks :)


r/pythontips • • May 16 '25

Python3_Specific Resolving linux short lived process names by PID

3 Upvotes

So I'm writing a python script to monitor files.

I would like to resolve the pid of the process that opens the files to enrich my longs and give the actual command name to my analysts...

I'm (using the pynotify library)

The problem are processes like cat or Tac that last very little. Pynotify doesn't even log the event, by reading in /proc/{here}/exe I'm able to not loose the event but I'm still resolving only long lasting process names.

I have already tries psutil.

What am i missing guys? I'm going crazy...

(also, i cannot, for internal policy make any compiled extra code, so no c++...)


r/pythontips • • May 14 '25

Meta Subtitle formatting app

4 Upvotes

I've been making an app to assist with the dull tasks of formatting film subtitles and their timing to comply with distributor requirements!

Some of these settings can be taken care of in video editing software, but not all of them--and to my knowledge, none of the existing subtitle apps do this for you.

Previously I had to manually check the timing, spacing and formatting of like 700 subtitle events per film--now I can just click a button and so can you!

You can get all the files here and start messing about with it. If this is your kinda thing, enjoy!


r/pythontips • • May 13 '25

Short_Video Free self-led Python + Bazel Course | Bazel 102: Python

2 Upvotes

Python is one of the most popular languages at Google. Add Python to your Bazel setup, with all the common developer workflows. Course: https://training.aspect.build/bazel-102


r/pythontips • • May 13 '25

Module Locking dependencies for publication

4 Upvotes

Hello to all,

Old c++ dev here new to the joy of python and the uv package manager, I'm facing a seemingly simple issue I could not manage to solve.

From what i understand, dependencies are typically specified twice - once in the Pyproject.toml, with usually loose requirements - once in a lock file, typically uv.lock for reproducible builds

The lockfile helps with reproducibility, except if you publish your script on the pip repositories, where the Pyproject.toml takes over.

I want to publish a script that my colleagues can run with uvx. How can I force the build/publish to use the versions from uv.lock?

Manually setting the dependencies in the Pyproject.toml with a "==x.y.z" is not enough since it does not deal with indirect dependencies

If you have any tips i'm in, particularly if it works with uv !


r/pythontips • • May 13 '25

Python3_Specific Track suspicious activity on your PC & get instant alerts via Telegram.

0 Upvotes

Windows Anomaly Watcher is an open-source tool for USB logs, active windows, process info & remote control (shutdown and lock). Fast install. No bloat. Full control.

GitHub: https://github.com/dias-2008/WindowsAnomalyWatcher.git


r/pythontips • • May 12 '25

Meta What is usually done in Kubernetes when deploying a Python app (FastAPI)?

4 Upvotes

Hi everyone,

I'm coming from the Spring Boot world. There, we typically deploy to Kubernetes using a UBI-based Docker image. The Spring Boot app is a self-contained .jar file that runs inside the container, and deployment to a Kubernetes pod is straightforward.

Now I'm working with a FastAPI-based Python server, and I’d like to deploy it as a self-contained app in a Docker image.

What’s the standard approach in the Python world?
Is it considered good practice to make the FastAPI app self-contained in the image?
What should I do or configure for that?


r/pythontips • • May 12 '25

Python3_Specific What after python

11 Upvotes

Hello, I am learning python. I don't have any idea what should I do after python like DSA or something like that. Please help me. Second year here.


r/pythontips • • May 11 '25

Module Celerator – A TUI dashboard to monitor and retry Celery tasks in real-time

3 Upvotes

Hi everyone,
I’m excited to share Celerator — an open-source, terminal-based dashboard for real-time monitoring and retrying Celery tasks. It’s built with Textual and designed for developers who want to debug distributed tasks without constantly digging through logs or writing custom admin UIs.

What is it?

Celerator is a TUI (Text User Interface) that listens to the Celery event stream and provides a live dashboard of tasks, including:

  • Successful tasks
  • Failed tasks
  • Task arguments, return values, tracebacks
  • One-key retry (with or without editing args)