Hello, I'm trying out a new blogging platform. I hope you like it. I just published a huge release of my Python OpenAPI Client library, [Clientele](https://github.com/phalt/clientele) and I wanted to talk through some of the big changes that I've added. The changes total over 1,000 lines of code, which makes the project almost twice the size of what it was previously. The cool thing is, despite these additions, the output of it is still the smallest, most lovable Python API client available (my own personal opinion, obviously!). If you're already using Clientele, you can easily upgrade with: ```sh pipx upgrade clientele ``` Then, when you run `clientele version` you should see this output: ```sh > clientele version clientele 0.7.0 ``` ## Changes ### Templates galore Previously, a lot of the generated code was produced by complicated [f-strings](https://realpython.com/python-f-strings/), and a few bits from templates. Templating with [Jinja](https://jinja.palletsprojects.com/en/2.10.x/) is way more manageable, and the project has now shifted to using them exclusively for file generation. ### Future generators and a "basic" client I've reorganised the folders of Clientele in a new pattern that will allow me to add new generators (think like, new templates) in the future. What could I do with this? Well, one debate I've had at my current job is whether or not we could use Clientele to make a decent [TypeScript](https://www.typescriptlang.org/) API client with it. Extending the scope of Clientele beyond Python is probably a long-term thing, but something I'd definitely like to explore if it keeps going well. Another debate I've been having is around API clients that don't use OpenAPI. The file structure of Clientele is sanely organised, why can't I make a "basic client" to keep my APIs consistent? [Well, now you can](https://phalt.github.io/clientele/usage/#generate-basic) with the `generate-basic` command! ### config.py The name `constants.py` in previous versions never felt correct to me, and after consultation with people using Clientele, I've settled on renaming it to `config.py`. The upgrade path is simple: **just renamed constants.py to config.py** and it'll work fine. ### Formatting code This is a big one. A lot of people use and love [black](https://black.readthedocs.io/en/stable/) for formatting code. It is so common in the python community now that I'd argue it is the default formatting method. Well, Clientele will now run black against the generated client so you don't have to do any additional formatting. ### Absolute paths Another very common python convention, imports in the generate code that used to look like this: ```python from . import client, schemas ``` Now look like this: ```python from app.support.my_api_client import client, schemas ``` Much cleaner, much more explicit, more Python-y code. ### Python 3.12 support Our CI test runners now run against the latest version of Python. ### Python 3.10+ union short-hand If you are using Python 3.10 (you should be) or later, the `typing.Union` syntax will now use the short hand `|` instead. So code that used to look like this: ```python def my_func( data: schemas.InputData ) -> typing.Union[schemas.GoodResponse, schemas.BadResponse]: ``` Will now be generated like this: ```python def my_func( data: schemas.InputData ) -> schemas.GoodResponse | schemas.BadResponse: ``` Yay for new short hands. ### Other misc bits - I've tested a bunch of OpenAPI schemas provided by the awesome Django plugin [drf-spectacular](https://github.com/tfranzel/drf-spectacular) and I am happy to say the compatibility with it is 100%. - A lot of values that should transform into Python snake-case properties just...weren't. But I've fixed that properly now, so it should remain consistent. - The documentation has had a nice spring clean and a big focus on readability. ## What's coming next? I am still actively using Clientele to make API clients in my job, and actively adding new features and fixing bugs in Clientele. You can check out the [GitHub issues](https://github.com/phalt/clientele/issues) to see what I am working on next (or to log a bug of your own). Here are the top 3 things I want to focus on for `0.8.0`: - `brew install clientele` - I'd love to do it, I have never added a package to [Brew](https://brew.sh/) before though. - Improved Async support. I like the `with async_client:` syntax over the `await` syntax. I think the context-manager also has better support for event loops too. So I'd like to improve that. - More OpenAPI compatibility. I think I cover 99% of common use cases, but edge cases will make Clientele's adoption as the go-to OpenAPI tool sky rocket. ## Using Clientele? Get in touch I'd love to hear from more people using Clientele, so reach out and let me know what you think! Thanks for reading this article, if you'd like to get in touch you can reach me through: - [Fosstodon](https://fosstodon.org/@proteanmachine) - [Email](mailto:[email protected]) - [GitHub](https://github.com/phalt) Paul