Python client library for Swagger Petstore API
Project description
Getting started
This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key special-key
to test the authorization filters.
How to Build
You must have Python 2 >=2.7.9
or Python 3 >=3.4
installed on your system to install and run this SDK. This SDK package depends on other Python packages like nose, jsonpickle etc.
These dependencies are defined in the requirements.txt
file that comes with the SDK.
To resolve these dependencies, you can use the PIP Dependency manager. Install it by following steps at https://pip.pypa.io/en/stable/installing/.
Python and PIP executables should be defined in your PATH. Open command prompt and type pip --version
.
This should display the version of the PIP Dependency Manager installed if your installation was successful and the paths are properly defined.
- Using command line, navigate to the directory containing the generated files (including
requirements.txt
) for the SDK. - Run the command
pip install -r requirements.txt
. This should install all the required dependencies.
How to Use
The following section explains how to use the Apimaticswaggerpetstore SDK package in a new project.
1. Open Project in an IDE
Open up a Python IDE like PyCharm. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.
Click on Open
in PyCharm to browse to your generated SDK directory and then click OK
.
The project files will be displayed in the side bar as follows:
2. Add a new Test Project
Create a new directory by right clicking on the solution name as shown below:
Name the directory as "test"
Add a python file to this project with the name "testsdk"
Name it "testsdk"
In your python file you will be required to import the generated python library using the following code lines
from apimaticswaggerpetstore.apimaticswaggerpetstore_client import ApimaticswaggerpetstoreClient
After this you can write code to instantiate an API client object, get a controller object and make API calls. Sample code is given in the subsequent sections.
3. Run the Test Project
To run the file within your test project, right click on your Python file inside your Test project and click on Run
How to Test
You can test the generated SDK and the server with automatically generated test cases. unittest is used as the testing framework and nose is used as the test runner. You can run the tests as follows:
- From terminal/cmd navigate to the root directory of the SDK.
- Invoke
pip install -r test-requirements.txt
- Invoke
nosetests
Initialization
Authentication
In order to setup authentication and initialization of the API client, you need the following information.
Parameter | Description |
---|---|
o_auth_client_id | OAuth 2 Client ID |
o_auth_redirect_uri | OAuth 2 Redirection endpoint or Callback Uri |
API client can be initialized as following.
# Configuration parameters and credentials
o_auth_client_id = 'o_auth_client_id' # OAuth 2 Client ID
o_auth_redirect_uri = 'o_auth_redirect_uri' # OAuth 2 Redirection endpoint or Callback Uri
client = ApimaticswaggerpetstoreClient(o_auth_client_id, o_auth_redirect_uri)
Class Reference
List of Controllers
PetController
Get controller instance
An instance of the PetController
class can be accessed from the API Client.
pet_controller = client.pet
upload_file
uploads an image
def upload_file(self,
pet_id,
additional_metadata=None,
file=None)
Parameters
Parameter | Tags | Description |
---|---|---|
petId | Required |
ID of pet to update |
additionalMetadata | Optional |
Additional data to pass to server |
file | Optional |
file to upload |
Example Usage
pet_id = 130
additional_metadata = 'additionalMetadata'
file = open("pathtofile", 'rb')
result = pet_controller.upload_file(pet_id, additional_metadata, file)
add_pet
Add a new pet to the store
def add_pet(self,
body)
Parameters
Parameter | Tags | Description |
---|---|---|
body | Required |
Pet object that needs to be added to the store |
Example Usage
body = Pet()
pet_controller.add_pet(body)
Errors
Error Code | Error Description |
---|---|
405 | Invalid input |
update_pet
Update an existing pet
def update_pet(self,
body)
Parameters
Parameter | Tags | Description |
---|---|---|
body | Required |
Pet object that needs to be added to the store |
Example Usage
body = Pet()
pet_controller.update_pet(body)
Errors
Error Code | Error Description |
---|---|
400 | Invalid ID supplied |
404 | Pet not found |
405 | Validation exception |
find_pets_by_status
Multiple status values can be provided with comma separated strings
def find_pets_by_status(self,
status)
Parameters
Parameter | Tags | Description |
---|---|---|
status | Required Collection |
Status values that need to be considered for filter |
Example Usage
status = [Status2Enum.AVAILABLE]
result = pet_controller.find_pets_by_status(status)
Errors
Error Code | Error Description |
---|---|
400 | Invalid status value |
find_pets_by_tags
Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
def find_pets_by_tags(self,
tags)
Parameters
Parameter | Tags | Description |
---|---|---|
tags | Required Collection |
Tags to filter by |
Example Usage
tags = ['tags']
result = pet_controller.find_pets_by_tags(tags)
Errors
Error Code | Error Description |
---|---|
400 | Invalid tag value |
get_pet_by_id
Returns a single pet
def get_pet_by_id(self,
pet_id)
Parameters
Parameter | Tags | Description |
---|---|---|
petId | Required |
ID of pet to return |
Example Usage
pet_id = 130
result = pet_controller.get_pet_by_id(pet_id)
Errors
Error Code | Error Description |
---|---|
400 | Invalid ID supplied |
404 | Pet not found |
update_pet_with_form
Updates a pet in the store with form data
def update_pet_with_form(self,
pet_id,
name=None,
status=None)
Parameters
Parameter | Tags | Description |
---|---|---|
petId | Required |
ID of pet that needs to be updated |
name | Optional |
Updated name of the pet |
status | Optional |
Updated status of the pet |
Example Usage
pet_id = 130
name = 'name'
status = 'status'
pet_controller.update_pet_with_form(pet_id, name, status)
Errors
Error Code | Error Description |
---|---|
405 | Invalid input |
delete_pet
Deletes a pet
def delete_pet(self,
pet_id,
api_key=None)
Parameters
Parameter | Tags | Description |
---|---|---|
petId | Required |
Pet id to delete |
apiKey | Optional |
TODO: Add a parameter description |
Example Usage
pet_id = 130
api_key = 'api_key'
pet_controller.delete_pet(pet_id, api_key)
Errors
Error Code | Error Description |
---|---|
400 | Invalid ID supplied |
404 | Pet not found |
StoreController
Get controller instance
An instance of the StoreController
class can be accessed from the API Client.
store_controller = client.store
create_place_order
Place an order for a pet
def create_place_order(self,
body)
Parameters
Parameter | Tags | Description |
---|---|---|
body | Required |
order placed for purchasing the pet |
Example Usage
body = Order()
result = store_controller.create_place_order(body)
Errors
Error Code | Error Description |
---|---|
400 | Invalid Order |
get_order_by_id
For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions
def get_order_by_id(self,
order_id)
Parameters
Parameter | Tags | Description |
---|---|---|
orderId | Required |
ID of pet that needs to be fetched |
Example Usage
order_id = 130
result = store_controller.get_order_by_id(order_id)
Errors
Error Code | Error Description |
---|---|
400 | Invalid ID supplied |
404 | Order not found |
delete_order
For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors
def delete_order(self,
order_id)
Parameters
Parameter | Tags | Description |
---|---|---|
orderId | Required |
ID of the order that needs to be deleted |
Example Usage
order_id = 130
store_controller.delete_order(order_id)
Errors
Error Code | Error Description |
---|---|
400 | Invalid ID supplied |
404 | Order not found |
get_inventory
Returns a map of status codes to quantities
def get_inventory(self)
Example Usage
result = store_controller.get_inventory()
UserController
Get controller instance
An instance of the UserController
class can be accessed from the API Client.
user_controller = client.user
create_users_with_array_input
Creates list of users with given input array
def create_users_with_array_input(self,
body)
Parameters
Parameter | Tags | Description |
---|---|---|
body | Required Collection |
List of user object |
Example Usage
body = [User()]
user_controller.create_users_with_array_input(body)
Errors
Error Code | Error Description |
---|---|
0 | successful operation |
create_users_with_list_input
Creates list of users with given input array
def create_users_with_list_input(self,
body)
Parameters
Parameter | Tags | Description |
---|---|---|
body | Required Collection |
List of user object |
Example Usage
body = [User()]
user_controller.create_users_with_list_input(body)
Errors
Error Code | Error Description |
---|---|
0 | successful operation |
get_user_by_name
Get user by user name
def get_user_by_name(self,
username)
Parameters
Parameter | Tags | Description |
---|---|---|
username | Required |
The name that needs to be fetched. Use user1 for testing. |
Example Usage
username = 'username'
result = user_controller.get_user_by_name(username)
Errors
Error Code | Error Description |
---|---|
400 | Invalid username supplied |
404 | User not found |
update_user
This can only be done by the logged in user.
def update_user(self,
username,
body)
Parameters
Parameter | Tags | Description |
---|---|---|
username | Required |
name that need to be updated |
body | Required |
Updated user object |
Example Usage
username = 'username'
body = User()
user_controller.update_user(username, body)
Errors
Error Code | Error Description |
---|---|
400 | Invalid user supplied |
404 | User not found |
delete_user
This can only be done by the logged in user.
def delete_user(self,
username)
Parameters
Parameter | Tags | Description |
---|---|---|
username | Required |
The name that needs to be deleted |
Example Usage
username = 'username'
user_controller.delete_user(username)
Errors
Error Code | Error Description |
---|---|
400 | Invalid username supplied |
404 | User not found |
get_login_user
Logs user into the system
def get_login_user(self,
username,
password)
Parameters
Parameter | Tags | Description |
---|---|---|
username | Required |
The user name for login |
password | Required |
The password for login in clear text |
Example Usage
username = 'username'
password = 'password'
result = user_controller.get_login_user(username, password)
Errors
Error Code | Error Description |
---|---|
400 | Invalid username/password supplied |
get_logout_user
Logs out current logged in user session
def get_logout_user(self)
Example Usage
user_controller.get_logout_user()
Errors
Error Code | Error Description |
---|---|
0 | successful operation |
create_user
This can only be done by the logged in user.
def create_user(self,
body)
Parameters
Parameter | Tags | Description |
---|---|---|
body | Required |
Created user object |
Example Usage
body = User()
user_controller.create_user(body)
Errors
Error Code | Error Description |
---|---|
0 | successful operation |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file apimaticswaggerpetstore-1.0.0.tar.gz
.
File metadata
- Download URL: apimaticswaggerpetstore-1.0.0.tar.gz
- Upload date:
- Size: 22.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4f75e988e928bbdb7482913d15e2b39821a5f1ab9ee84928a76cfeea49ab4b6 |
|
MD5 | 05438ed76cf1590ffd6bb8b6f96511a9 |
|
BLAKE2b-256 | 6212992a07371090ee2d251b1a15c2cb70b8441c02881b14f20117e88b43eb2d |
File details
Details for the file apimaticswaggerpetstore-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: apimaticswaggerpetstore-1.0.0-py3-none-any.whl
- Upload date:
- Size: 33.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9d2d421be32b3535fa8585d660e8dce71aa9c082f74ef9106def3119a84675e |
|
MD5 | b017a628a9a1f1b224edc5f8ed82b442 |
|
BLAKE2b-256 | 472583735b9dde939c3173d13e6996d892e0b2a9c7220e74a182a292c895da5b |