shapeways.client¶
-
class
shapeways.client.Client(consumer_key, consumer_secret, callback_url=None, oauth_token=None, oauth_secret=None)[source]¶ Api client for the Shapeways API http://developers.shapeways.com
The API uses OAuth v1 to authenticate clients, so the following steps must be used.
- Create a client
- Connect to API and get request token and authentication url
- Send user to authentication url
- Verify callback from authentication url
Example:
client = Client("key", "secret") url = client.connect() # redirect user to `url` # capture response url from authentication callback client.verify_url(response_url) # make api requests info = client.get_api_info()
Constructor for a new
shapeways.client.ClientParameters: - consumer_key (str) – The API key for your app
- consumer_secret (str) – The API secret key for your app
- callback_url (str) – The url that should be redirected to after successful authentication with Shapeways OAuth
- oauth_token (str) – The OAuth token obtained from calls to connect/verify
- oauth_secret (str) – The OAuth secret obtained from calls to connect/verify
-
add_model(params)[source]¶ Make an API call POST /models/v1
Required Parameters:
file- str (the file data)fileName- strhasRightsToModel- boolacceptTermsAndConditions- bool
Optional Parameters:
uploadScale- floattitle- strdescription- strisPublic- boolisForSale- boolisDownloadable- booltags- listmaterials- dictdefaultMaterialId- intcategories- list
Parameters: params (dict) – dict of necessary parameters to make the api call Returns: model upload information Return type: dict Raises: Exceptionwhen any of the required parameters are missing
-
add_model_file(model_id, params)[source]¶ Make an API call POST /models/{model_id}/files/v1
Required Parameters:
file- str (the file data)fileName- strhasRightsToModel- boolacceptTermsAndConditions- bool
Optional Parameters:
uploadScale- float
Parameters: - model_id (int) – the id of the model to upload the file for
- params (dict) – dict of necessary parameters to make the api call
Returns: file upload information
Return type: dict
Raises: Exceptionwhen any of the required parameters are missing
-
add_model_photo(model_id, params)[source]¶ Make an API call POST /models/{model_id}/photos/v1
Required Parameters:
file- str (the file data)
Optional Parameters:
title- strdescription- strmaterialId- intisDefault- bool
Parameters: - model_id (int) – the id of the model to upload the photo for
- params (dict) – dict of necessary parameters to make the api call
Returns: photo upload information
Return type: dict
Raises: Exceptionwhen the required parameter is missing
-
add_to_cart(params)[source]¶ Make an API call POST /orders/cart/v1
Required Parameters:
modelId- int
Optional Parameters:
materialId- intquantity- int
Parameters: params (dict) – dict of necessary parameters to make the api call Returns: whether or not the call was successful Return type: dict Raises: Exceptionwhen the required parameter is missing
-
connect()[source]¶ Get an OAuth request token and authentication url
Returns: the authentication url that the user must visit or None on error Return type: str or None
-
delete_model(model_id)[source]¶ Make an API call DELETE /models/{model_id}/v1
Parameters: model_id – the id of the model to delete Returns: information whether or not it was successful Return type: dict
-
get_api_info()[source]¶ Make an API call GET /api/v1
Returns: api info Return type: dict
-
get_cart()[source]¶ Make an API call GET /orders/cart/v1
Returns: items currently in the cart Return type: dict
-
get_categories()[source]¶ Make an API call GET /categories/v1
Returns: information about all categories Return type: dict
-
get_category(category_id)[source]¶ Make an API call GET /categories/{category_id}/v1
Parameters: category_id (int) – the category to fetch information for Returns: information about a specific category Return type: dict
-
get_material(material_id)[source]¶ Make an API call GET /materials/{material_id}/v1
Parameters: material_id (int) – the id of the material to fetch Returns: specific materials info Return type: dict
-
get_materials()[source]¶ Make an API call GET /materials/v1
Returns: information about all materials Return type: dict
-
get_model(model_id)[source]¶ Make an API call GET /models/{model_id}/v1
Parameters: model_id – the id of the model to fetch Returns: data for a specific model Return type: dict
-
get_model_file(model_id, file_version, include_file=False)[source]¶ Make an API call GET /models/{model_id}/files/{file_version}/v1
Parameters: - model_id (int) – the id of the model to get the file from
- file_version (int) – the file version of the file to fetch
- include_file (bool) – whether or not to include the raw file data in the response
Returns: the file information
Return type: dict
-
get_model_info(model_id)[source]¶ Make an API call GET /models/{model_id}/info/v1
Parameters: model_id – the id of the model to fetch Returns: information for a specific model Return type: dict
-
get_models(page=None)[source]¶ Make an API call GET /models/v1
Returns: information about all user’s models Return type: dict
-
get_price(params)[source]¶ Make an API call POST /price/v1
Required Parameters:
volume- floatarea- floatxBoundMin- floatxBoundMax- floatyBoundMin- floatyBoundMax- floatzBoundMin- floatzBoundMax- float
Optional Parameters:
materials- list
Parameters: params (dict) – dict of necessary parameters to make the api call Returns: pricing information for the paramsgivenReturn type: dict Raises: Exceptionwhen any of the required parameters are missing
-
get_printer(printer_id)[source]¶ Make an API call GET /printers/{printer_id}/v1
Parameters: printer_id (int) – the printer to fetch information for Returns: information about a specific printer Return type: dict
-
get_printers()[source]¶ Make an API call GET /printers/v1
Returns: information about all printers Return type: dict
-
update_model_info(model_id, params)[source]¶ Make an API call PUT /models/{model_id}/info/v1
Optional Parameters:
uploadScale- floattitle- strdescription- strisPublic- boolisForSale- boolisDownloadable- booltags- listmaterials- dictdefaultMaterialId- intcategories- list
Parameters: - model_id (int) – the id of the model to get the file from
- params (dict) – dict of necessary parameters to make the api call
Returns: the model information
Return type: dict
-
url(path)[source]¶ Generate the full url for an API path
client = Client("key", "secret") url = client.url("/api/") # "https://api.shapeways.com/api/v1"
Parameters: path (str) – The API path to get the url for Returns: the full url to pathReturn type: str
-
verify(oauth_token, oauth_verifier)[source]¶ Get an access token and setup OAuth credentials for further use
If you have the full url or query string from the authentication callback then you can use
shapeways.client.Client.verify_url()which will parse the correct parameters from the query string and callshapeways.client.Client.verify()Parameters: - oauth_token (str) – the
oauth_tokenparameter from the authentication callback - oauth_verifier (str) – the
oauth_verifierparameter from the authentication callback
- oauth_token (str) – the
-
verify_url(url)[source]¶ Parse parameters and properly call
shapeways.client.Client.verify()If you already have the
oauth_tokenandoauth_verifierparameters parsed, useshapeways.client.Client.verify()directly instead.Parameters: url (str) – The response url or query string from the authentication callback