1

I am facing with the problem of ModuleNotFoundError: No module named 'swagger_client' when trying to run the below code.

How it is possible to import swagger_client?

I want to have access to a custom api.

my code :

from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint


# create an instance of the API class
api_instance = swagger_client.BookingApi()
reservationId =  # Long | reservation id

try: 
    # Cancel reservation
    api_response = api_instance.cancel_reservation(reservationId)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling BookingApi->cancelReservation: %s\n" % e)
gtopal
  • 544
  • 1
  • 9
  • 35
  • Does this answer your question? [swagger_client in python trying to use Strava API](https://stackoverflow.com/q/55657275/113116) – Helen Jan 09 '20 at 14:36

5 Answers5

0

Are you sure that you've installed the correct package? I ran pip3 install swagger_client and pip3 install swaggerclient and it it told me that there was no matching distribution.

Here is a link to what appears to be a the most popular Python swagger implementation for Django, along with a good quick start guide that looks similar to what you are trying to accomplish.

Otherwise, this list contains all community-driven integrations of Swagger in their respective languages. Lots of different ones to choose from when working with Python.

Calvin
  • 131
  • 1
  • 4
0

I am not sure it is still relevant, but what worked for me to set up swagger_ client is that after I downloaded the specific client for the API I want to use, i.e., once I got the python-client-generated.zip from the swagger editor, I extracted it and then run the python setup.py install in the same folder I extracted it to. Then I just picked the folders called swagger_client and swagger_client.egg-info copied it to my virtualenv/lib/python3.X/site-packages folder where all the rest of the packages I use are located. After that I could import swagger_client to all my Django files.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Greg
  • 134
  • 9
0

You can install swagger in your project by below command. (Python)

pip install --upgrade git+git://github.com/Yelp/bravado@swaggerpy
Nids Barthwal
  • 2,205
  • 20
  • 12
0

Use this

pip install zuora-swagger-client
Shubham Tomar
  • 166
  • 1
  • 9
0

I had this issue while following the docs for a partner company's internal API, and found that installing swagger_client was actually not the issue.

Swagger is often used for the documentation SDK examples, and is not an officially published package. Often the REST API endpoint itself for custom APIs is tech stack-agnostic, so you are able to use whatever best fits your existing languages/frameworks for interacting with API endpoints.

wraasch
  • 405
  • 3
  • 13