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.

  1. Create a client
  2. Connect to API and get request token and authentication url
  3. Send user to authentication url
  4. 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.Client

Parameters:
  • 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:

  1. file - str (the file data)
  2. fileName - str
  3. hasRightsToModel - bool
  4. acceptTermsAndConditions - bool

Optional Parameters:

  1. uploadScale - float
  2. title - str
  3. description - str
  4. isPublic - bool
  5. isForSale - bool
  6. isDownloadable - bool
  7. tags - list
  8. materials - dict
  9. defaultMaterialId - int
  10. categories - list
Parameters:params (dict) – dict of necessary parameters to make the api call
Returns:model upload information
Return type:dict
Raises:Exception when 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:

  1. file - str (the file data)
  2. fileName - str
  3. hasRightsToModel - bool
  4. acceptTermsAndConditions - bool

Optional Parameters:

  1. 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:

Exception when 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:

  1. file - str (the file data)

Optional Parameters:

  1. title - str
  2. description - str
  3. materialId - int
  4. isDefault - 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:

Exception when the required parameter is missing

add_to_cart(params)[source]

Make an API call POST /orders/cart/v1

Required Parameters:

  1. modelId - int

Optional Parameters:

  1. materialId - int
  2. quantity - 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:Exception when 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:

  1. volume - float
  2. area - float
  3. xBoundMin - float
  4. xBoundMax - float
  5. yBoundMin - float
  6. yBoundMax - float
  7. zBoundMin - float
  8. zBoundMax - float

Optional Parameters:

  1. materials - list
Parameters:params (dict) – dict of necessary parameters to make the api call
Returns:pricing information for the params given
Return type:dict
Raises:Exception when 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:

  1. uploadScale - float
  2. title - str
  3. description - str
  4. isPublic - bool
  5. isForSale - bool
  6. isDownloadable - bool
  7. tags - list
  8. materials - dict
  9. defaultMaterialId - int
  10. categories - 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 path
Return 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 call shapeways.client.Client.verify()

Parameters:
  • oauth_token (str) – the oauth_token parameter from the authentication callback
  • oauth_verifier (str) – the oauth_verifier parameter from the authentication callback
verify_url(url)[source]

Parse parameters and properly call shapeways.client.Client.verify()

If you already have the oauth_token and oauth_verifier parameters parsed, use shapeways.client.Client.verify() directly instead.

Parameters:url (str) – The response url or query string from the authentication callback