Using as a module

You can use pyxelrest as a python module as well.

import pyxelrest

configuration = {'petstore': {'open_api': {'definition': 'https://petstore.swagger.io/v2/swagger.json'}}}
pyxelrest.load(configuration)

# Import statement MUST be after the call to pyxelrest.load as the modules are generated by this call
from pyxelrest.generated import petstore

# Functions are available as python functions within petstore (in this case) and can be used as such
user = petstore.getUserByName("test")

# {'id': 9999, 'username': 'test', 'firstName': 'test', 'lastName': 'test', 'email': 'test@test.com', 'password': 'test', 'userStatus': 0}
print(user)

Refer to configuration section for more details on the available options.

Generating functions

You can manually (re)generate functions by calling pyxelrest.load() and providing your own services configuration.

You can access the functions available for each REST API by using the specific pyxelrest.generated.{my_api} module where {my_api} is the name of the configuration section as shown in the example.

Converting REST API responses

You can provide a custom converter if the default one is not enough.

You could for example return pandas.DataFrame for every JSON dict response as in the following sample:

import pyxelrest
import pandas

configuration = {'petstore': {'open_api': {'definition': 'https://petstore.swagger.io/v2/swagger.json'}}}

pyxelrest.load(configuration, to_response=lambda response: pandas.DataFrame([response.json()]))

# Import statement MUST be after the call to pyxelrest.load as the modules are generated by this call
from pyxelrest.generated import petstore

# Functions are available as python functions within petstore (in this case) and can be used as such
user = petstore.getUserByName("test")

#      id username firstName  ... password   phone userStatus
# 0  9999     test      test  ...     test    test          0
print(user)