Questions tagged [python]

Python is a dynamically typed, high-level interpreted programming language. Its design focuses on clear syntax, an intuitive approach to object-oriented programming, and making the right way to do things obvious. Python supports modules and exceptions, and has an extensive standard module library. Python is general-purpose and thus used widely, from the web to embedded systems.

Filter by
Sorted by
Tagged with
0 votes
0 answers
12 views

When packaging a Python module, is there a way to let the user know what OS packages will be required?

I'm trying to package a Python library that works with an LDAP server. When installing on Ubuntu, my library requires libldap2 and libsasl2. When installing it on CentOS, there are different libraries....
Robert Rapplean's user avatar
0 votes
1 answer
88 views

How does one add observability to python code without affecting code quality?

We're working an agile project and designing as we go on a new python commandline app / systemd service for some fancy in-house project. Right now, we're supposed to be adding an observability / ...
Peter Turner's user avatar
  • 6,905
-3 votes
2 answers
129 views

Polymorphism with variable default argument count

I'm in the process of writing a library in Python, and I've run into a design problem concerning the use of polymorphism. I have an ABC with abstract method 'foo': class A(ABC): @abstractmethod ...
Jan van Wijk's user avatar
1 vote
0 answers
93 views

How to structure your Python code with asynchronous and synchronous parts

I have a Python FastAPI server application which naturally guides you towards the asynchronous paradigm. For legacy reasons, I have to support two backends, one which is purely synchronous and one ...
user3058865's user avatar
-3 votes
1 answer
194 views

Better way to type casting an object from one custom class to another [closed]

I have one object, its class inherits all property from GUI class, that takes and some values and one function during instantiation, that handles click and upon receiving the click it calls the ...
novice's user avatar
  • 95
0 votes
0 answers
33 views

Best design pattern for integrating Google OAuth with existing JWT token-based authentication system

We currently have a backend authentication mechanism in place that utilizes JWT tokens. Users sign in or sign up using email and password, and upon successful authentication, the backend issues JWT ...
Samiksha Garg's user avatar
-2 votes
1 answer
92 views

Are there some best practices how to build a client library for an API?

I was tasked to create an API client library for our already existing API. I tried to research some ways how to approach this but couldn't find anything. Are there some best practices how to build ...
user3630290's user avatar
2 votes
2 answers
503 views

Is this architecture overkill? What is a good way to architect this software?

I have an algorithm I am trying to implement that has steps 1 to 5. There are several different ways I could implement each step. Each calculation step is essentially just an astronomy calculation, ...
Hunter's user avatar
  • 187
0 votes
2 answers
99 views

Using an instance method or a function with conditional logic based on type

I'm developing a data pipeline in Python. We receive a variety of different types of data set that we need to process (e.g. xml, json, csv and some Excel workbooks) - where processing involves parsing ...
henryn's user avatar
  • 101
0 votes
3 answers
81 views

Python API - store data in SQL AND NoSql

I am a student and am currently programming an API in Python. Among other things, it is possible to register, log in, create a user profile with data, etc. I would like to be able to store and ...
flo's user avatar
  • 1
1 vote
1 answer
79 views

How to test integration with an infinite generator

I'm struggling to (integration) test a component that makes use of an infinite generator. Background: At a really high level, this component is essentially a "middleman" in a kafka workflow. ...
Luke Nelson's user avatar
-2 votes
4 answers
325 views

Compare version numbers

I need to compare versions of a software. The requirement is that I need to know if a given version is older (smaller), same or newer (higher) than another one. The version format is XX.X.XX where: ...
Marcus's user avatar
  • 29
-1 votes
1 answer
102 views

How to structure a modular MITM proxy with python

To explain what I'm trying to accomplish. Sometimes I visit website1.com, here I can download Linux ISOs but it's a bit annoying because it has a lot of ads, some of which are launched via javascript ...
Daviid's user avatar
  • 49
-3 votes
1 answer
108 views

Learn a framework on a project, or mix languages between backend services [closed]

I am designing my next project, which will do various domain-specific tasks, but all that will be controlled and used via a generic crud web app. I have been professionally using Java with Spring for ...
rafal.sz's user avatar
6 votes
1 answer
2k views

Why are there two ways to retrieve values from a dictionary in Python?

In Python there are basically two ways to get a value from a dictionary: dictionary["key"] dictionary.get("key") Is there any - maybe historical - reason for this behavior? I ...
Thomas Junk's user avatar
  • 9,543
1 vote
2 answers
205 views

Splitting up large SQLAlchemy model

Anybody have advice on splitting up a large SQLAlchemy model into smaller parts? I have a ~2000 line model called Article that is becoming difficult to manage. We often have to scroll and scroll to ...
caseym's user avatar
  • 119
2 votes
1 answer
248 views

In python when is absolutely preferable use a class than a module?

Python is the language I use most in this period. My background in Java Before start learning Python I have programmed in Java language. In Java all code is written inside the methods of a class and ...
User051209's user avatar
0 votes
0 answers
53 views

How to structure my DB setup?

I have made a small project to try and learn to implement SQLite-DBs into my projects. For the DB part, I use sqlmodel and followed their tutorial. For the creation of the engine however, they use a ...
Jan's user avatar
  • 203
3 votes
1 answer
163 views

How to structure repositories for a small number of entities?

I am working on a project implemented in DDD style, and I use Repository architecture pattern to persist domain changes. I have multiple roles in domain layer, and that's what raises my question - how ...
lubitelpospat's user avatar
2 votes
1 answer
138 views

How do I structure my functions (and classes?) which interact with my Database/ORM?

So I am working on my first project using SQLite and SQLModel as ORM. Creating and handling the first table in my database was easily structured: A function for each CRUD-Operation. But now I have ...
Jan's user avatar
  • 203
2 votes
3 answers
133 views

Which association should be in the class diagram

there are a vehicle class and customer class . In short, in the customer class there is a function that shows 'can this person or company rent that car'.The function uses a object of vehicle and ...
Tunahan's user avatar
  • 31
1 vote
0 answers
48 views

Endpoint design for single and bulk requests

I'm working on a project in Python and want to get it hosted for others to use, the internal recommendation has been to host it on AzureML (it is a non-machine learning model, but follows the same ...
evaless's user avatar
  • 11
13 votes
3 answers
2k views

Using `any` to indicate a wildcard value

I'm writing a validator class to validate certain request objects against a known format. Rule declarations and the validator will both be written entirely in Python, and I don't need to store the ...
JSBձոգչ's user avatar
  • 1,450
2 votes
0 answers
148 views

Managing environments in a FastAPI app using Docker

Bit of context: I'm an Economics major that somehow ended up developing an API that's becoming a whole software project, so please bear with me. So, after I got asked to add logs I noticed I should ...
Juan C's user avatar
  • 121
2 votes
2 answers
681 views

Why access the attributes of a Python class by reference?

Attribute references and instantiation In this link, that is part of the official Python documentation, I have found the following information: Class objects support two kinds of operations: ...
User051209's user avatar
2 votes
1 answer
169 views

Design patterns for long chains of computations in python (functions vs classes?)

A recurring pattern which I see in my code is chaining together a lot of functions. This is the result of a large number of processing steps needed for a given task. This could be e.g. a data ...
Jan's user avatar
  • 203
1 vote
3 answers
223 views

What is more Pythonic way to handle try-except errors?

I have two different options in mind: def foo(): try: # do something interesting except: # report error here return bar bar = foo() or def foo(): # do something ...
merovingian's user avatar
0 votes
0 answers
47 views

Splitting a data set for CNN

Suppose, I have a tensor tfDataSet as follows: data3d = [ [[7.042 9.118 0. 1. 1. 1. 1. 1. 0. 0. 1. ] [5.781 5.488 7.47 0. 0. 0. 0. 1. 1. 0. 0. ...
user366312's user avatar
1 vote
2 answers
58 views

Hierachy and API design for a CSS-selector-related Python library

I'm writing a Python CSS-selector library that allows one to write these kinds of expressions in Python as a pet project. The goal of the library is to represent selectors in a flat, intuitive and ...
InSync's user avatar
  • 111
3 votes
2 answers
150 views

Conceptual Software Design: Managing Large Number of LEDs with Raspberry Pi

Question Summary I am writing a program that will run on a Raspberry Pi 4b+ designed to manage hundreds of LEDs, as well as a few other devices (such as small motors). This is for a project I am a ...
Raspberry Intern's user avatar
3 votes
2 answers
3k views

How can I nicely pass on a class instance in python?

I am rewriting a streamlit app that is an interface to a laboratory management system (LMS). This means, that I have to make a lot of requests to that LMS through its python library (PyBIS). The way ...
Jan's user avatar
  • 203
-1 votes
2 answers
112 views

Architecture for EOD (end of day) stock exchange prices

I need to work out the architecture for a NASDAQ frontend charting application (a desktop app in .Net). Note that this is NOT for real-time quotes. NASDAQ provides an api that gives historical pricing,...
rmcsharry's user avatar
  • 117
0 votes
1 answer
103 views

Storing Data For Consumption in Python

I have a program which needs some constant data, in JSON-like format. However, this data only needs to be consumed by my Python program, and by making it Python code, I can include types like datetime....
pigrammer's user avatar
  • 111
-1 votes
1 answer
272 views

Best-Practice for organizing properties in a python class [closed]

When using properties in a Python class, you have a lot of boilerplate code. Is there a best practice to hide the code for the getters and setters? I know about @dataclass, but the problem is mainly ...
allo's user avatar
  • 178
24 votes
6 answers
8k views

Best practice for redundant conditions in if-elif-else statements

What is considered better practice? Case 1: if n == 0: doThis() elif n < 0: doThat() elif n > 0: doSomethingElse() Case 2: if n == 0: doThis() elif n < 0: doThat() else: ...
Nikhil Kumar's user avatar
0 votes
0 answers
60 views

How should I organize build instructions for third-party packages?

In my projects I have several third-party Python packages which I need to build from source (because there are no .whl packages published for the versions+platforms I need). Currently these packages ...
oliver's user avatar
  • 111
6 votes
3 answers
2k views

Best design practice when one python method passes most of its arguments to another method

My code has 2 python methods defined, m1 and m2. m1 receives 6 arguments - p1,p2,p3...p6. It uses p1 in its own code, but passes p2-p6 to m2. Is there a recommended programming style here to prevent ...
str31's user avatar
  • 71
7 votes
1 answer
794 views

Matching dependency versions across multiple Python projects

I have about 60 repos containing Python packages, currently using setuptools in a setup.py (run via pip install) to manage third-party dependencies. Most of these packages need to be installed on a ...
Jason C's user avatar
  • 465
-1 votes
4 answers
449 views

Leetcode: 2327. Number of People Aware of a Secret and Problem with programming skill in general

On day 1, one person discovers a secret. You are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the ...
jason's user avatar
  • 15
1 vote
1 answer
88 views

How to show type introspection in UML

I'm modeling a part of Python/Qt GUI code which uses reflection to construct a collection of widgets, in a form. The code works like this: There is a Model which has attributes of various types, ...
Daniël Schenk's user avatar
0 votes
2 answers
212 views

Build an API for a graph app with + 30 millions data points

I am quite new to design software and especially graphs. So I am working on a full-stack app with a back-end built on FastAPI (python) et front-end on React. I need to create 4 graphs on a single page ...
intern_2004_uk's user avatar
2 votes
2 answers
281 views

Best practices for unit testing when breaking down functions into smaller ones

Say we have a function of the form def func(num: int) -> int: num = num + 1 num = 2 * num num = num**3 return num and let us act like each line is a long computation so that we ...
grebs's user avatar
  • 39
0 votes
0 answers
55 views

Organizing screen resolutions?

Does it make sense to organize screen resolutions? I write a lot of selenium tests, often which I need to choose a resolution for the browser. I ended up creating a dictionary with some of the more ...
Marcel Wilson's user avatar
0 votes
1 answer
189 views

What are the performance implications of using multiple threads versus single-threaded [closed]

What are the performance implications of using multiple threads versus single-threaded asynchronous programming in Python 3.9? I've been working with Python for quite a while and I'm familiar with ...
user avatar
0 votes
1 answer
131 views

Should you add the name of the package to the module/package name in Python? [closed]

I'm looking for some best practices for readability (and clean code in general) for naming modules/classes within more extensive projects. More specifically, is it reasonable to add the package's name ...
Thomas Vanhelden's user avatar
0 votes
1 answer
246 views

Automatic detection of semantic versioning based on Python type hints

I am the maintainer of a Python library that uses semantic versioning. Skip the next paragraph if you are familiar with what it means. The rough and dirty explanation of semantic versioning is as ...
JMU's user avatar
  • 9
3 votes
2 answers
261 views

Should a decorated function know about its decorator from a semantic point of view?

In this toy example some_function is... some function that takes a dict as an input and modifies it in place somehow. def some_function(dct: dict): """Do something to the items in ...
Alexander Soare's user avatar
-1 votes
2 answers
263 views

Should this code be made testable? [closed]

My code looks roughly like 40 def send_pubkey( s: socket ) -> None: 41 '''Transmit own public key unencrypted.''' 42 ...
Vorac's user avatar
  • 7,129
2 votes
1 answer
182 views

two diffrent database in unit of work

I will explain my problem in the form of an example. Suppose we want to use both databases in a transaction. Data is edited in database 1 (for example, Postgres) and then added to database 2. Finally, ...
Amir Hosein's user avatar
2 votes
2 answers
163 views

How should I structure an update script that handles the output of another module?

I have a large (>1,000 LOC) Python ETL script - call it fetch_and_transform_data.py - that fetches data from a remote database, appends the raw data to a local table, does some transformations and ...
Josh Friedlander's user avatar

1
2 3 4 5
41