Backend API
SwellPy is our API wrapper written in Python with type support aimed at backend development. It provides convenient methods for performing CRUD operations on your Swell store data using a server-side Python application.
In this guide, we’ll review the installation and initialization steps, some commonly used Swell-Py methods, and this library’s caching behavior.
To install SwellPy, check out this repo.
See our Backend API docs for code examples using Python.
Clone SwellPy and build locally. We’re in the process of adding the package to PyPI, which will simplify installation. In the meantime, you can install the package locally using the following steps:
git clone git@github.com:swellstores/swellpy.git
pip install [relative path to swellpy]
swell = Swell({ store_id: "SWELL_STORE_ID", api_key: "SWELL_API_KEY" )}
response = swell.products.create({'name': 'my-product-slug'})
SwellPy can be used for querying and retrieving backend data like account, product, and cart details. Some of the most commonly used methods in the library include:
- get(), list(), update(), create(), and delete()
- orders.convert_cart_to_order()
- webhooks.list_events()
In this section, we’ll go over what each method is used for, the parameters for each one, and see an example of how it’s used.
- get(), list(), update(), create(), and delete()
The get/list/update/delete methods are CRUD operations used to manage and edit your Swell store data and content models. You can also use these CRUD operations to implement custom logic to your store’s data. The parameters for this method are url and data.
response = swell.products.list({ limit:25, page:1 ]);
Caching
SwellPy provides LRU caching for better performance for the get() and list() methods.
Rate limiting is set by default at two calls per second, but can be updated as part of the initialization options. Keep in mind that the Swell backend API will throttle requests that exceed fair-use limits (commonly resulting from out-of-control scripts).
Now that we've reviewed SwellPy, we’re ready to explore Swell’s backend API. Continue on to learn about errors and querying.