# publish.features()

### Parameters

**`features_dict`***`:dict:`*[`Dictionary`](https://github.com/rasgointelligence/RasgoDocs/blob/main/rasgo-0.1/pyrasgo-0.3/features/broken-reference/README.md) `to publish as Rasgo Features`

`{`\
`"sourceTable": "mandatory DB.SCHEMA.TABLE where features are",`\
`"features": [`\
`{`\
`"columnName": "mandatory_field_name_in_table",`\
`"displayName": "Optional Pretty Name",`\
`"dataType": "mandatory sql type",`\
`"description": "optional display text",`\
`"tags": [`\
`"optional",`\
`"list of strings",`\
`"apply only to this feature"`\
`],`\
`"attributes": [`\
`{ "key": "value"},`\
`{"optional": "apply only to this features" }`\
`]`\
`}`\
`],`\
`"dimensions": [`\
`{`\
`"columnName": "mandatory_field_name_in_table",`\
`"displayName": "Optional Pretty Name",`\
`"dataType": "mandatory sql type",`\
`"granularity": "mandatory noun ..."`\
`}`\
`],`\
`"status": "Production | Sandbox",`\
`"tags": [`\
`"optional",`\
`"list of strings",`\
`"apply to all features"`\
`],`\
`"attributes": [`\
`{"key": "value"},`\
`{"optional": "apply to all features"}`\
`],`\
`"script": "OptionalFile.py",`\
`"gitRepo": "Optional"`\
`}`

### Return Object

[Rasgo FeatureSet](https://github.com/rasgointelligence/RasgoDocs/blob/main/pyrasgo/features/broken-reference/README.md)

### Sample Usage

Create new features from a dict

```python
	features_dict = rasgo.prepare_feature_set_dict(600)
    print('My Dict:', features_dict)
	
	features_dict = {
        'sourceTable': 'pandas_by_DATE_YEAR_2021_02_05_00_42', 
        'features': [
            {
                'columnName': 'NEXT_MONTH', 
                'dataType': 'integer', 
                'displayName': 'PANDAS_NEXT_MONTH_2021_02_05_00_42', 
                'description': 'Feature that contains PANDAS_NEXT_MONTH_2021_02_05_00_42 data',
                'tags': ['test'],
                'attributes': [{'FeatureKey': 'FeatureValue'}]
            },
            {
                'columnName': 'NEXT_MONTH', 
                'dataType': 'integer', 
                'displayName': 'PANDAS_NEXT_MONTH_2021_02_05_00_42', 
                'description': 'Feature that contains PANDAS_NEXT_MONTH_2021_02_05_00_42 data'
            }
            ], 
        'dimensions': [
            {
                'columnName': 'YEAR', 
                'dataType': 'integer', 
                'granularity': 'test'
            }, 
            {
                'columnName': 'DATE', 
                'dataType': 'string', 
                'granularity': 'day'
            }
            ], 
        'tags': ['test', '02/05/2021', 'Pandas'],
        'attributes': [{'Key1': 'Value1'}],
        'status': 'Production'
    }
    features = rasgo.publish.features(features_dict)
    print(features)
```

Publish changes to an existing feature

```python
feature = rasgo.get_feature(1557)
features_dict = feature.to_dict()
print('My Feature:', features_dict)

# Changes feature values by interacting with dict
# Example: Update Name
feautures_dict["features"][0]["displayName"] = "New Feature Name"

feature = rasgo.publish_features(features_dict)
print(feature)
```

Publish changes to all features in a FeatureSet

```python
features_dict = rasgo.prepare_feature_set_dict(600)
print('My FeatureSet:', features_dict)


# Changes feature values by interacting with dict
# Example: Add tags to all features
feautures_dict["tags"] = ["new tag", "apply to all features"]

features = rasgo.publish_features(features_dict)
print(features)
```

{% hint style="info" %}
Columns in your DataSource table that are not referenced in either the "dimensions" or "features" list will be ignored
{% endhint %}

### Best Practices / Tips

{% hint style="warning" %}
TIP: Feature name warning message

If you receive the error: "APIError: Failed to create Feature {\_\_\_}. This name is already in use in your organization. Feature names must be unique." this is a sign that a feature already exists with this name.

Options to remedy are:

* If the existing feature is named correctly and the feature you are trying to upload needs a new name: change the displayName attribute in your dict.
* If the existing feature is simply an earlier run of this feature, instruct the function to overwrite it by passing in the param *if\_exists='edit'*
* If the existing feature is named incorrectly, navigate to the WebApp to change that feature's name, then re-upload
  {% endhint %}
