Packaging approach for client and server code

I’m working on a project that has an HTTP API component and a client component. The HTTP API component is a Flask app and the client component is a class that uses requests to handle HTTP calls. What’s a good approach for packaging up this code? Should I make two separate Python packages where one package is the client and the other package is the server (Flask app)? Or should I just make a single package that contains the client and server code? Any suggestions on how to structure and package up such a project would be helpful.

I would have two packages, one for client and one for the server.
That way you do not depend on flask if all you want to do is use the API via its client.

1 Like

Having them as two separate packages would be the easiest approach. But how would I handle the naming of the packages? Would I call them something like mypackage-client and mypackage-server?

I like the idea of having everything in one package because all the code is in one repository. Would it be possible to do something like pip install mypackage[server] to just install the server-side code? Otherwise, doing pip install mypackage would just install the client-side code.

You could experiment with the pip install mypackage[server].
I guess that means the server gets the client code as well.

But there is no reason that you cannot build 2 packages from one repos.

1 Like

Neither the server nor the client is an optional feature of the other, so use two packages. I imagine very few scripts would ever import both the server and the client.

I like that idea. Do you know of any projects that do this that I can use as an example? How would you structure such a repository? Something like this?

myproject/
├── README.md
├── pyproject.toml
├── tests/
├── docs/
└── src/
    ├── mypackage-client/
    │   ├── __init__.py
    │   └── client.py
    └── mypackage-server/
        ├── __init__.py
        └── server.py

I have a number of small CLI tools in one repo and you can see what I did here: GitHub - barry-scott/CLI-tools: A collection of command line (CLI) tools
You could have

myproject/
README.md
tests/
docs/
mypackage-client/
    pyproject.toml
    src/
        __init__.py
        client.py
mypackage-server/
    pyproject.toml
    src/
        __init__.py
        server.py

1 Like