1

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?

asked Nov 8, 2022 at 16:08
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? Commented Nov 8, 2022 at 17:58
  • 2
    thanks @KilianFoth. I was overthinking this and needed a 2nd opinion to stop spending too much time on minor things Commented Nov 8, 2022 at 18:06

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.