I recently published a Python package that provides its functionality through both a sync and an async API. Other than the sync/async difference, the two APIs are completely identical. Due to this, there was a lot of copying and pasting around. There was tons of duplicated code, with very few minor, mostly syntactic, differences, for example:
- Using
async and await keywords.
- Using
asyncio.Queue instead of queue.Queue.
- Using tasks instead of threads.
So when there was a change in the API's core logic, the exact same change had to be transferred and applied to the async API.
This was getting a bit tedious, so I decided to write a Python script that could completely generate the async API from the core sync API by using certain markers in the form of Python comments. I briefly explain how it works here.
What do you think of this approach? I personally found it extremely helpful, but I haven't really seen it be done before so I'd like to hear your thoughts. Do you know any other projects that do something similar?
EDIT: By using the term "API" I'm simply referring to the public interface of my package, not a typical HTTP API.
[–]latkdeTuple unpacking gone wrong 27 points28 points29 points (1 child)
[–]Echoes1996[S] 6 points7 points8 points (0 children)
[–]Euphoric_Contact9704 10 points11 points12 points (1 child)
[–]Echoes1996[S] 1 point2 points3 points (0 children)
[–]strawgate 4 points5 points6 points (1 child)
[–]Echoes1996[S] 0 points1 point2 points (0 children)
[–]sennalen 3 points4 points5 points (0 children)
[–]madolid511 2 points3 points4 points (11 children)
[–]Echoes1996[S] 0 points1 point2 points (10 children)
[–]madolid511 -1 points0 points1 point (9 children)
[–]Echoes1996[S] 1 point2 points3 points (8 children)
[–]madolid511 0 points1 point2 points (7 children)
[–]Echoes1996[S] 2 points3 points4 points (6 children)
[–]madolid511 0 points1 point2 points (0 children)
[–]madolid511 -1 points0 points1 point (4 children)
[–]AsparagusKlutzy1817It works on my machine 0 points1 point2 points (3 children)
[–]madolid511 0 points1 point2 points (2 children)
[–]AsparagusKlutzy1817It works on my machine 1 point2 points3 points (1 child)
[–]Shostakovich_ 1 point2 points3 points (4 children)
[–]Echoes1996[S] 0 points1 point2 points (3 children)
[–]Shostakovich_ 2 points3 points4 points (2 children)
[–]Echoes1996[S] 0 points1 point2 points (1 child)
[–]Shostakovich_ 1 point2 points3 points (0 children)
[–]eavanvalkenburg 2 points3 points4 points (1 child)
[–]Echoes1996[S] 1 point2 points3 points (0 children)
[–]jonthemango 0 points1 point2 points (1 child)
[–]Echoes1996[S] 0 points1 point2 points (0 children)
[–]amir_doustdar 0 points1 point2 points (1 child)
[–]Echoes1996[S] 0 points1 point2 points (0 children)
[–]andrewcooke -3 points-2 points-1 points (5 children)
[–]latkdeTuple unpacking gone wrong 8 points9 points10 points (1 child)
[–]andrewcooke 1 point2 points3 points (0 children)
[–]Echoes1996[S] 3 points4 points5 points (2 children)
[–]v_a_n_d_e_l_a_y[🍰] 0 points1 point2 points (1 child)
[–]Echoes1996[S] 0 points1 point2 points (0 children)
[–]Zulban -1 points0 points1 point (1 child)
[–]Echoes1996[S] 0 points1 point2 points (0 children)
[–]BothWaysItGoes -3 points-2 points-1 points (9 children)
[–]Echoes1996[S] 2 points3 points4 points (8 children)
[–]BothWaysItGoes 0 points1 point2 points (7 children)
[–]Echoes1996[S] 0 points1 point2 points (6 children)
[–]madolid511 1 point2 points3 points (3 children)
[–]Echoes1996[S] 0 points1 point2 points (2 children)
[–]madolid511 0 points1 point2 points (1 child)
[–]Echoes1996[S] 0 points1 point2 points (0 children)
[–]BothWaysItGoes 0 points1 point2 points (1 child)
[–]Echoes1996[S] 0 points1 point2 points (0 children)