From the documentation here:
Tables are compatible with a range of input data structures. If you’ve seen the tutorial you’ll have seen a queryset being used, however any iterable that supports len() and contains items that expose key-based accessed to column values is fine.
So you can create your own wrapper class around your API calls which requests the length of your data when len() is called.
Something like this might work, although you'd probably want to optimize it to only access the API and return just the items needed, not the entire data set as is suggested below.
class ApiDataset(object):
def __init__(self, api_addr):
self.http_api_addr = api_addr
self.data = None
def cache_data(self):
# Access API and cache returned data on object.
if self.data is None:
self.data = get_data_from_api()
def __iter__(self):
self.cache_results()
for item in self.data['objects']:
yield item
def __len__(self):
self.cache_results()
return self.data['total_count']
Using this setup, you would pass in an APIDataset instance to the django-tables2 Table constructor.