# A New Python API

**URL:** <https://meta.discourse.org/t/a-new-python-api/191974>\
**Category:** Development\
**Created:** [May 28, 2021, 8:54pm UTC](https://meta.discourse.org/t/a-new-python-api/191974 "2021-05-28T20:54:42Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Grayden\_Shand](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/grayden_shand/32/166586_2.png) [@Grayden\_Shand](https://meta.discourse.org/u/Grayden_Shand)\
**Post date:** [September 30, 2021, 8:25pm UTC](https://meta.discourse.org/t/a-new-python-api/191974/4 "2021-09-30T20:25:21Z")

</div>

> [@JonathanShaw](#):
>
> To do something similar in php we’d have to rely on magic methods and so lose the benefit of IDE autocompletion etc. But might be a wortwhile price to pay.

That’s a good point, IDE autocompletion will not be of much help here. It might be worth using a different library if that’s important to you.

> [@JonathanShaw](#):
>
> What’s the advantage of this approach over simply passing the url as an argument: `client.get(url)`?

Since each method chain returns a new client, one advantage I can think of is storing a specific method chain in a variable and re-using it for subsequent calls. For example, let’s say you had a list of data for new posts that you wanted to create.

```plaintext
post_data = [
  {
    "raw": "Hello World!",
    "topic_id": 123,
    ...
  },
  {
    "raw": "Tester",
    "topic_id": 501,
    ...
  },
  ...
]

```

You could store the “New post” method chain and re-use it to create each of the posts in the list.

```plaintext
new_post_endpoint = client.posts.json

for post in post_data:
  new_post_endpoint.post(data=post) 

```

You might be able to imagine other scenarios where this ability to re-use a client could be useful. Beyond that, there’s not a huge advantage over just passing the url like you suggested. I encourage you to read about the [Universal Client](https://universal-client.readthedocs.io/en/latest/) library which contains some information about the rational for this type of approach.

Also, for a PHP specific implementation of this approach, check out [SendGrid’s PHP API](https://sendgrid.com/blog/using-php-to-implement-a-fluent-interface-to-any-rest-api/). I was inspired to build this when I read about [SendGrid’s Python API](https://sendgrid.com/blog/using-python-to-implement-a-fluent-interface-to-any-rest-api/).

---

_[View the full topic](https://meta.discourse.org/t/a-new-python-api/191974)._
