# Sharing
URL: https://docs.datarobot.com/en/docs/api/dev-learning/python/admin/sharing.html

# Sharing

Once you have created entities in DataRobot, you may want to share them with collaborators.
DataRobot provides an API for sharing the following entities:

> Data sources and data stores ( seeDatabase connectivityfor more info on connecting to JDBC databases)DatasetsProjectsCalendar filesModel deployments (seeDeployment sharingfor more information on sharing deployments)Use Cases (Sharing for Use Cases is slightly different than what’s documented on this page. SeeUse Case sharingfor more information and examples.)

## Access levels

Entities can be shared at varying access levels.
For example, you can allow someone to create projects from a data source you have built without allowing them to delete it.

Each entity type uses slightly different permission names intended to specifically convey what kind of actions are available.
These roles fall into three categories.
These generic role names can be used in the sharing API for any entity.

For the complete set of actions granted by each role on a given entity, see the [UI documentation for roles and permissions](https://docs.datarobot.com/en/docs/get-started/acct-mgmt/data-sharing/roles-permissions.html).

> OWNERUsed for all entities.Allows any action including deletion.READ_WRITEKnown asEDITORon data sources and data stores.Allows modifications to the state, such as renaming and creating data sources from a data store, butnotdeleting the entity.READ_ONLYKnown asCONSUMERon data sources and data stores.For data sources, enables creating projects and predictions; for data stores, only allows you to view them.

When a user’s new role is specified as `None`, their access will be revoked.

In addition to the role, some entities (data sources and data stores) allow separate control over whether a new user should be able to share that entity further.
When granting access to a user, the `can_share` parameter determines whether that user can, in turn, share this entity with another user.
When this parameter is set as false, the user in question has all the access to the entity granted by their role and can remove themselves if desired, but are unable to change the role of any other user.

## Examples

Transfer access to the data source from [mailto:old_user@datarobot.com](mailto:old_user@datarobot.com) to [mailto:new_user@datarobot.com](mailto:new_user@datarobot.com).

```
import datarobot as dr

new_access = dr.SharingAccess(
   "new_user@datarobot.com",
   dr.enums.SHARING_ROLE.OWNER,
   can_share=True,
)
access_list = [dr.SharingAccess("old_user@datarobot.com", None), new_access]

dr.DataSource.get('my-data-source-id').share(access_list)
```

To check access to a project:

```
import datarobot as dr

project = dr.Project.create('mydata.csv', project_name='My Data')

access_list = project.get_access_list()

access_list[0].username
```

To transfer ownership of all projects owned by your account to [mailto:new_user@datarobot.com](mailto:new_user@datarobot.com) without sending notifications:

```
import datarobot as dr

# Put path to YAML credentials below
dr.Client(config_path= '.yaml')

# Get all projects for your account and store the ids in a list
projects = dr.Project.list()

project_ids = [project.id for project in projects]

# List of emails to share with
share_targets = ['new_user@datarobot.com']

# Target role
target_role = dr.enums.SHARING_ROLE.OWNER

for pid in project_ids:

   project = dr.Project.get(project_id=pid)

   shares = []

   for user in share_targets:

      shares.append(dr.SharingAccess(username=user, role=target_role))

   project.share(shares, send_notification=False)
```

---
