# Deploying Python functions in Watson Machine Learning #

You can deploy Python functions in Watson Machine Learning the same way that you can deploy models\. Your tools and apps can use the Watson Machine Learning Python client or REST API to send data to your deployed functions the same way that they send data to deployed models\. Deploying Python functions gives you the ability to hide details (such as credentials)\. You can also preprocess data before you pass it to models\. Additionally, you can handle errors and include calls to multiple models, all within the deployed function instead of in your application\.

## Sample notebooks for creating and deploying Python functions ##

For examples of how to create and deploy Python functions by using the Watson Machine Learning [Python client library](https://ibm.github.io/watson-machine-learning-sdk/), refer to these sample notebooks:

<!-- <table> -->

| Sample name                                                                                                    | Framework          | Techniques demonstrated                                                                                                                                                      |
| -------------------------------------------------------------------------------------------------------------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Use Python function to recognize hand\-written digits](https://dataplatform.cloud.ibm.com/exchange/public/entry/view/1eddc77b3a4340d68f762625d40b64f9) | Python             | Use a function to store a sample model and deploy it\.                                                                                                                       |
| [Predict business for cars](https://dataplatform.cloud.ibm.com/exchange/public/entry/view/61a8b600f1bb183e2c471e7a64299f0e)                                                                                  | Hybrid(Tensorflow) | Set up an AI definition  <br>Prepare the data  <br>Create a Keras model by using Tensorflow  <br>Deploy and score the model  <br>Define, store, and deploy a Python function |
| [Deploy Python function for software specification](https://dataplatform.cloud.ibm.com/exchange/public/entry/view/56825df5322b91daffd39426038808e9)                                                          | Core               | Create a Python function  <br>Create a web service  <br>Score the model                                                                                                      |

<!-- </table ""> -->

The notebooks demonstrate the six steps for creating and deploying a function:

<!-- <ol> -->

1.  Define the function\.
2.  Authenticate and define a space\.
3.  Store the function in the repository\.
4.  Get the software specification\.
5.  Deploy the stored function\.
6.  Send data to the function for processing\.

<!-- </ol> -->

For links to other sample notebooks that use the Watson Machine Learning [Python client library](https://ibm.github.io/watson-machine-learning-sdk/), refer to [Using Watson Machine Learning in a notebook](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/ml-samples-overview.html)\.

## Increasing scalability for a function ##

When you deploy a function from a deployment space or programmatically, a single copy of the function is deployed by default\. To increase scalability, you can increase the number of replicas by editing the configuration of the deployment\. More replicas allow for a larger volume of scoring requests\.

The following example uses the Python client API to set the number of replicas to 3\.

    change_meta = {
                    client.deployments.ConfigurationMetaNames.HARDWARE_SPEC: {
                                           "name":"S",
                                           "num_nodes":3}
                }
    
    client.deployments.update(<deployment_id>, change_meta)

## Learn more ##

<!-- <ul> -->

 *  To learn more about defining a deployable Python function, see **General requirements for deployable functions** section in [Writing and storing deployable Python functions](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/ml-deploy-py-function-write.html)\.
 *  You can deploy a function from a deployment space through the user interface\. For more information, see [Deployment spaces](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/ml-spaces_local.html)\.

<!-- </ul> -->

**Parent topic:**[Managing predictive deployments](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/ml-deploy-general.html)

<!-- </article "role="article" "> -->