I'm working on a python wrapper for a REST API. I'm using python data classes to store the shape of the JSON response of each endpoint so developers have features like autocomplete and objects they can use from the response.
In 99% of the cases, I can maintain a separate python file for each end point.
So for /cars
endpoint, I have a file called cars.py
and for /bikes
, bikes.py
. Each python file has a self contained @dataclass
representing the JSON returned by functions within the endpoint.
Following this practice, there's endpoint like /maintainence/
and an associated maintainance.py
. This endpoint can return a car or bike object plus some extra info.
What's the recommended good practice to import the data model from bike.py
or car.py
into maintainence.py
?
Do I create a separate python files just for the modules?
Is it okay to import the data class from adjacent python files?
-
1Sure, it's okay to import data classes from another file, even a very small file. What other sensible alternative is there even?Kilian Foth– Kilian Foth2022年11月08日 17:58:07 +00:00Commented Nov 8, 2022 at 17:58
-
2thanks @KilianFoth. I was overthinking this and needed a 2nd opinion to stop spending too much time on minor thingsrsn– rsn2022年11月08日 18:06:52 +00:00Commented Nov 8, 2022 at 18:06