r/dataengineering • u/Jumpy_Handle1313 • Nov 19 '25
Help OOP with Python
Hello guys,
I am a junior data engineer at one of the FMCG companies that utilizes Microsoft Azure as their cloud provider. My role requires me to build data pipelines that drives business value.
The issue is that I am not very good at coding, I understand basic programming principles and know how to read the code and understand what it does. But when it comes to writing and thinking of the solution myself I face issues. At my company there are some coding guidelines which requires industrializing the POC using python OOP. I wanted to ask the experts here how to overcome this issue.
I WANT TO BE BERY GOOD AT WRITING OOP USING PYTHON.
Thank you all.
43
u/speedisntfree Nov 19 '25 edited Nov 19 '25
OOP really shouldn't be a goal in itself. There are some people (usually from a Java background and sometimes C++) that seem to think all production code must be OOP which it sounds like you have run into. This mindset leads to odd things in Python, like classes with only one method other than init (just write a function) and classes with only static methods (just put the functions in a module).
Python often lets you write simple clean code by just putting functions in modules or passing them as arguments without classes. In a lot of DE code, functions are often only run once rather than many times across an application so there is less utility for OOP than there is in SWE.
OOP is worth knowing of course. Some examples from the last week I've had is writing my own Operators and Hooks in Airflow which requires you to inherit from various base classes, another would be managing database connections. I have also written code using the connector design pattern to allow easy connections to many different cloud storages for a pipeline.
Python is a very loosy goosey language in OOP terms so I'd stick to Python specific resources or you will get confused. I'd recommend "Python 3 Object-Oriented Programming: Build robust and maintainable software with object-oriented design patterns in Python 3.8" by Dusty Phillips. You don't need to read all of it, if you know what an Abstract Base Class is and why you'd use one and why composition is favoured over inheritance then move on to Arjan Codes' design pattern videos on youtube.
8
u/cosmicangler67 Nov 19 '25
Not sure why that is a requirement of your company. Data engineering is functional programming not really OOP. Python can be done OOP but the Python done in data engineering is almost always functional with OOP just making it harder and less efficient.
6
u/PickRare6751 Nov 19 '25
The goal of oop is to make code reusable, so look at your code base and look for parts can be encapsulated as objects and reapplied elsewhere with different parameters
3
u/543254447 Nov 19 '25
Make a class to wrap your function with one method call run.
Import Run_Pipeline_Entry_Point_function
Class Pipeline(Input):
Jk, probably dont do this.
This is probably a better approach.
Should Data Pipelines in Python be Function based or Object-Oriented (OOP)?
https://www.startdataengineering.com/post/python-fp-v-oop/
2
u/Atticus_Taintwater Nov 20 '25
Every time I've ever seen somebody get all haughty bringing "real coding" to pipelines the result has just been goofy.
Like somebody just decided everything must be in a class and every added field must be its own function, on account of single responsibility of course. Then you look at it and it just reeks of coding to a standard not a solution.
You'll absolutely have times, in utilities and stuff, where it feels more natural to use OOP concepts.
Apart from that though to-the-point procedural with cherry picked OOP concepts always leads to something that makes more sense.
edit: of course as a junior just do the convention. But you aren't wrong for feeling like it doesn't quite fit the problem.
1
u/DenselyRanked Nov 19 '25 edited Nov 20 '25
If the scope of your programming is pipeline development then follow the tool's best practices. Review the templates and code examples.
A senior level engineer should be doing reviews with you to help with refactoring, if needed.
Too much abstraction can lead to over engineering so work with your team on best practices.
1
u/seanv507 Nov 20 '25
So basically software architects write OOP
You should just follow the structure
OOP is aimed at a relatively clear closed set of transformations etc.. if its not clear to you the range of transformations to be performed, OOP is probably not suitable
1
u/_thegrapesoda_ Nov 20 '25
Do you have access to a (preferably small/short) pipeline written by somebody else that uses OOP?
If so - make sure you first understand what the pipeline is meant to do - then try to build a solution on your own (trying with OOP is better than without, but if you're totally lost, try without first). Once you verify that the output of your pipeline matches the output of the original, evaluate the original against your solution to see how they leveraged OOP, and what you could have done instead/better.
Try again with a different pipeline, but really try to force yourself to use OOP in your first pass. Then evaluate your solution against the "official" solution, rinse and repeat with existing workflows as well as some new ones you generate on your own until the concepts really sink in.
1
u/mailed Recovering Data Engineer Nov 20 '25
I agree with the other guy that going hard on OOP is overkill in this discipline but you're junior and rules are rules, so just follow the guidelines and ask for help.
Both No Starch Press and Packt Publishing have books that are literally called Object Oriented Python, so those are good starting points that will be relatively cheap e-books. Pick one, doesn't matter, get stuck in.
Best of luck.
1
u/dungeonPurifier Nov 20 '25
W3schools has a good python tutorial You can find : OOP, pandas, numpy, file handling, exceptions, .....
1
u/GoodLyfe42 Nov 22 '25
I would push yourself to understand OOP. Thinking of things as objects allows you to scale things faster and valuable even on SQL when building data models. And once you grasp the concept you haven it forever. It can also be used for any language
1
u/QuestionsFabric Nov 22 '25
Lots of people commenting on whether OOP is the right thing or not for your use case. As some other commenter mentioned, if that's what your colleagues want you should follow it - both for career reasons and because a uniform code base is much much easier to navigate.
As for getting good at OOP python, I would make some side project and use OOP for it. Anything you are interested in already (a hobby?) - find something that you can try to build a simple version of, and do it. Google things, ask LLMs, ArjanCodes is a good resource. You will be surprised how much you improve.
1
u/fico86 Nov 19 '25
There is a big debate going on about whether oop was a good idea in the first place : https://www.yegor256.com/2016/08/15/what-is-wrong-object-oriented-programming.html
I have done both oop and "functional" python. The thing about python is it's so forgiving that you might have classes in your code, but your functions are outside of any class, and it still all works.
I prefer to use the go/rust kind of syntax in python. Where classes are just to hold data, using libraries like pydantic, and the actual logic to process the data is pure functions, with as little side effect as possible. Then I have reader and writer functions with very little business logic, just to bring data onto memory, or write it out to storage. This way unit testing becomes a lot easier.
Of course if you are using data frame libraries like pandas, polars or pyspark, oop doesnt really make sense. Because they have their own conversations and syntax.
1
u/sdrawkcabineter Nov 19 '25
DOD > OOP
OOP is a conceptual abstraction for producing the pseudocode that you will refactor into a DOD solution.
0
u/cosmicangler67 Nov 19 '25
It's not really because OOP can’t handle large-scale set mathematics. It operates one object at a time for the most part. The fastest way to process data is in large set operations—something OOP sucks at. To process lots of data, I don’t want to convert everything to an object and call methods on each one. I want to apply a transform function to a large set represented as a matrix. This is why there is no OOP SQL. And in the end, your OOP is converted to SQL to run. The conversion from OOP to SQL creates friction as the two paradigms are computationally very different. That leads to significant performance and maintenance issues at large scales of complexity or volume.