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
-4 votes
0 answers
41 views

python celery with clean architecture

I am learning and trying to develop a python project using clean architecture. Following is the project structure as below: - proj/ - entities/ # contain entities eg User, user.py - usecases/ # ...
0 votes
3 answers
106 views

How to handle dependencies between microservices all called within one large service

We are working on a suite of Python 'services' each of which is basically an application that does some calculations based on a domain (data) model and returns the results. These services are designed ...
3 votes
1 answer
114 views

What is the anti-pattern for modules that group objects of the same type? [closed]

In MVC, I often seen all models in a models.py module, all views in a views.py module, and the controller - you guessed it - in a controller.py module. In other projects, I sometimes see all exception ...
0 votes
1 answer
108 views

Where should research and production code reside in git?

We have research code that consists of Jupyter notebooks and large data files. At the same time, we also have production code that consists of Python source and CloudFormation templates. There is ...
12 votes
2 answers
2k views

Designing a Python string validation library

My employer has a significant number of company-internal strings which require format validation. For instance, order number AAA-BBB-CCC, stock number AB-123456 or factory ABC1 - Regex with extras (...
-1 votes
0 answers
19 views

How to apply modularity by function in Python web apps?

I've been working on expanding my skillset and teaching myself Python to develop a web app using Flask. The reason Python was chosen was for its viability for machine learning applications. I expect ...
0 votes
1 answer
66 views

Sending and receiving results from microservices

I welcome everyone. I'm trying to understand microservice architecture. The task such: is 2 services. The first - for example, books rooms in a hotel. The second is something like a console interface ...
1 vote
1 answer
146 views

Storing multiple instances on a Singleton?

RefactoringGuru's example Singleton in Python has an _instances dictionary field class Singleton(type): _instances = {} def __call__(cls, *args, **kwargs): if cls not in cls....
1 vote
1 answer
588 views

Exchange data between python and angular with flask

I am trying to determine which is the best arquitecture to my application, I am planning to use python, mysql, angular and flask as an intermediate between python and angular. I have all the shots of ...
8 votes
4 answers
4k views

Prime symbol in Python variable name

So I'm a terrible person and I want to name a variable in my mathy-python3 code s′ (that's U+2032 PRIME). I was under the impression Unicode literals work as identifiers in Python 3, which is why my ɣ,...
3 votes
3 answers
8k views

Is it possible to have setup and tear down methods run only for specific unittests?

I currently have a test class with a setUp method for creating a temp file and a tearDown method for deleting a temp file. However, only some of the the test_ methods in that class require this ...
14 votes
5 answers
17k views

How to avoid bidirectional class and module dependencies

To give some context, I'm using python. We have the following package structure: /package_name /request.py # defines class Request /response.py # defines class Response Let also assume ...
0 votes
1 answer
1k views

Django - should I create related objects immediately or on demand?

Let's say you have a ForeignKey MyModel.related_model and this related_model has all fields either null=True or default=something. Like User.userprofile which I use on several places in my project. ...
1 vote
3 answers
174 views

Is adding functions to a namespace/module after imports an anti-pattern?

In my python codebase I have several open source dependencies, eg. pandas, plotly, etc. Some of these are missing some functions that I'd rather they have. I sometimes add functions to these libraries ...
0 votes
1 answer
132 views

Where to create repository instances?

I've several repositories. To make them testable, I add the ORM session in the constructor. class Repository: def __init__(session): self.session = session def save(object): self.session()...
0 votes
2 answers
176 views

Is there a better way to trigger API calls from an on Prem SQL Server without using a job scheduler?

I'm not sure if this is the correct area to ask this question, quite honestly, I'm not sure how to phrase the question because I don't know if what I'm thinking is possible. I'm trying to figure out a ...
-1 votes
3 answers
146 views

Is it better to override methods in classes or make methods general?

I am creating the backend of a microservice that will serve as a tool to see in real time how the company's employees are distributed by projects and what days they have assigned to each one. The ...
-1 votes
1 answer
93 views

Design suggestions for my simple data-analysis program

I need to create a program with the purpose of cross-referencing personal info from a spreadsheet(s), to check for conflicts of interest between clients of 3 different law firms. All of this client ...
1 vote
1 answer
1k views

How to distribute a project with all its dependencies?

We are developing a system for a customer that does not want to allow installation of packages from outside repositories. The project is in Python and defines its dependencies via setuptools; most of ...
1 vote
2 answers
823 views

Python method docstring: to use or not to use Args: Returns:

Default docstring from PyCharm automatically creates template with Args: and Returns: sections. However I have observed that this prompts people to say obvious things, frequently just stating the ...
1 vote
2 answers
101 views

Dependency resolution of tasks which have crontab information

I want to illustrate my problem statement with a use case. I am building a trading system that acts as a container for deploying trading strategies. The trading strategy comprises dependent tasks. Let'...
1 vote
2 answers
157 views

How to deal with constants that are shared between multiple packages?

I'm looking at creating my first packages to clean up my codebase. Below is a very simplified version of my current project structure: my_project/ |-database.py |-app_1.py |-app_2.py |-constants.py ...
1 vote
2 answers
333 views

Software Design: Decoupling when highly dependent on a third party library

As part of an university project I am currently working on an eeg-biosignal classifier. While the project itself doesn't really focus on design ("anything that works") I am trying to learn ...
2 votes
2 answers
187 views

Design pattern for constructing and linking up objects that form a graph

I am working on a simple library that will help me work with prescription drugs. For instance, DrugBank contains a list of FDA approved drugs, and, importantly, how these drugs interact with one ...
1 vote
3 answers
228 views

Are interchangeable types a security vulnerability? Are they good vectors for attack?

Suppose you are given a python API: def onArgumentReceived(x): doWhatever(x) # expects a unicode string I am not a security expert by any stretch of the imagination, however on the face of this, ...
0 votes
1 answer
138 views

Multiple models/controllers python app

I am trying to tinker with the MVC pattern and I have a problem when trying to design the MVC structure. I need a model for products, however as I need to manage more and different data, I can help ...
3 votes
3 answers
237 views

Is there an approach to keep a large number of conditionals maintainable

I work on a survey that has a lot of questions. This means we have a lot of columns/variables to work with. This translates to a lot of conditionals that have to be done a certain way according to a ...
4 votes
2 answers
2k views

Raising new exceptions in Python backward-incompatible?

I'm trying to know if we can freely raise new exceptions when maintaining methods of a versioned library. Here is a minimal example of what the change could be: import logging def check_id_old(...
1 vote
1 answer
186 views

How to handle i18n on a microservice architecture project?

I'm currently developing a bot for Discord that sends news over webhooks to multiple servers and I've decided to separate that news onto it's own microservice because the bot runs multiple instances ...
1 vote
2 answers
477 views

add function to input of builtin python logger

For simplicity, assume my application logs only dictionaries. I want to add a step to Python logging for my application to prevent logging any dictionary with the key password, i.e., def clean_log(...
0 votes
2 answers
149 views

Encoding text to image and decoding back to text

(FYI: I asked this question on stack overflow and was directed here) My problem is as follows: I have a dashboard running on a server at customer premises which updates every 15 minutes The dashboard ...
0 votes
1 answer
112 views

How can I use builders for products with incompatible interfaces?

I am working on a program to automatically design heater units based on varying client specifications. The process for creating each heater is quite involved and requires multiple optional steps ...
-1 votes
0 answers
89 views

class docstring or __doc__ docstring for namedtuple?

Based on different answers to this question: Adding docstrings to namedtuples? attribute docstring from collections import namedtuple Point = namedtuple('Point', 'x y') Point.__doc__ = '''\ A 2-...
0 votes
2 answers
88 views

Design Review: Queuing tasks to add rows of data followed by task to send email

I need to send personalized emails to a filtered set of users (~100,000) on every fortnight. I am using Marketing cloud API for it. The way I am thinking of designing the system is as follows: ...
8 votes
4 answers
3k views

How to perform consistent hashing on any Python object that works with hash()?

I have a Python library that performs a kind of calculation given a parameter-object. A requirement of the parameter object is that it be both hashable and serializable. It's a long calculation, so it ...
3 votes
1 answer
255 views

Data processing pipeline design for processing data

I have a use case for which I need to build a data processing pipeline Customer contact leads data coming from different data sources like csv, data base, api has to be first mapped to a universal ...
0 votes
0 answers
91 views

Python Typechecking versus TypedDicts?

From what I understand from this answer, it is not possible to use a typeddict and typechecking in a function. So for example, if one has a function: def some_func(some_int: int, some_dict:...
1 vote
2 answers
168 views

String representation in Python runtimes

Python is one of the few languages to support a string data type of code points (Unicode Scalar Values). I'm also wanting to creating a language that has this same characteristic, but I need to ...
1 vote
2 answers
98 views

Using class attributes as globals in Python - is there a catch?

I have found myself in the habit of using code like this. class glb: "just for holding globals" args = None # from argparse conf = None # from configparser def main(): ......
0 votes
1 answer
82 views

What is an apporpriate design pattern when dealing with Pandas and databases?

We're dealing with a lot of "data analysis", basically different sorts of data mangling, aggregations and calculations using Pandas. Usually, the data is time series data. All underlying ...
0 votes
1 answer
121 views

Should SSDP be considered as a go-to option for local network discovery in software development?

I am currently working on a Raspberry Pi based robotics project that I would like to connect to a realtime customized control panel/dashboard, mostly for debugging purposes. I created a test setup ...
3 votes
4 answers
459 views

How to avoid code duplication when else and except are the same?

A simplified version of my code looks like this: def process( object ): try: if suitedForA( object ): try: methodA( object ) except: ...
1 vote
1 answer
150 views

Elegant way to handle two options, when both is also an option

In the simplest case, I have some code where the user may want to do one thing (a), another thing, (b), or both (a+b). The options are reasonably complex and have their own functions, but I would like ...
2 votes
1 answer
190 views

Access control to Django App running on private server

I am a self-learning programmer (with a fair share of python knowledge), and currently a company asked to develop a simple application so that they can track employee expenses (and I thought of using ...
0 votes
2 answers
150 views

Is there some easy way to refactor deeply coupled python code

I recently took on a long ago python project which has some weird code style that I can't pinpoint. e.g. # this is a params and value package? opts={ infile="xxx", outfile="xxx" } ...
1 vote
1 answer
96 views

Should a LoggingHandler log?

I wrote a custom log handler that has a config file and uses a service on the network. Now I'm wondering if it should itself log. Pro: Everyone should log, it helps track errors, especially when you'...
5 votes
4 answers
326 views

Is it better to iterate over data once and do multiple complex operations, or to iterate multiple times with simpler operations?

Here I'm working in Python, but it's more of a language agnostic question, unless specific language features makes it clear that an option is better than the other. I get my raw data from a REST API, ...
14 votes
3 answers
7k views

Python for large projects

Are there any resources out there on how to architect large, industrial strength Python projects? I'd like to start on an ambitious personal project, but I'm not really sure how to architect it and ...
29 votes
2 answers
11k views

Why is universal newlines mode deprecated in Python?

I just noticed that the universal newline feature of file operations seems to be on its way out. The documentation for Python 3.5 open's mode parameter indicates that it's deprecated: 'U' ...
0 votes
1 answer
184 views

Should I Add Integration Or Unit Tests To Django Views

I am currently exploring adding unit tests to my Django REST Framework project. I totally understand adding unit tests for other components of the app like models. However, I'm stuck at testing views. ...

1
2 3 4 5
39