0

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?

2
  • 1
    Sure, it's okay to import data classes from another file, even a very small file. What other sensible alternative is there even? Nov 8, 2022 at 17:58
  • thanks @KilianFoth. I was overthinking this and needed a 2nd opinion to stop spending too much time on minor things
    – rsn
    Nov 8, 2022 at 18:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.