Package: slack-scim
slack-scim - Slack SCIM API ClientThis library provides ways to call Slack's SCIM APIs in the Pythonic way.SCIM (System for Cross-domain Identity Management)Slack SCIM APIGetting StartedIt's pretty easy and intuitive to use this library 😉 Try with your admin user token!$pipinstallslack-scim
Collectingslack-scimUsingcachedslack_scim-1.0.6-py2.py3-none-any.whl(20kB)Installingcollectedpackages:slack-scim
Successfullyinstalledslack-scim-1.0.6

$python

>>>importos
>>>importslack_scim
>>>client=slack_scim.SCIMClient(token=os.environ["SLACK_ADMIN_TOKEN"])>>>importlogging
>>>logging.basicConfig(level=logging.DEBUG)>>>users=client.search_users(filter="restricted eq 1",count=5)DEBUG:slack_scim.v1.client:***SCIMAPIRequest***
GEThttps://api.slack.com/scim/v1/Users?filter=restricted+eq+1&count=5authorization:(redacted)user-agent:Python/3.8.2slack_scim/1.0.6Darwin/19.4.0
content-type:application/x-www-form-urlencoded;charset=utf-8


DEBUG:slack_scim.v1.client:***SCIMAPIResponse***
GEThttps://api.slack.com/scim/v1/Users?filter=restricted+eq+1&count=5200OK
date:Sun,26Apr202003:53:44GMT
server:Apache
strict-transport-security:max-age=31536000;includeSubDomains;preload
referrer-policy:no-referrer
x-slack-backend:h
vary:Accept-Encoding
x-xss-protection:0x-frame-options:SAMEORIGIN
connection:close
transfer-encoding:chunked
content-type:application/json;charset=utf-8
x-via:haproxy-www-4mte{"totalResults":2,"itemsPerPage":2,"startIndex":1,"schemas":["urn:scim:schemas:core:1.0"],"Resources":[{"schemas":["urn:scim:schemas:core:1.0"],"id":"WRDCW4CHX","externalId":"","meta":{"created":"2019-12-14T01:26:43-08:00","location":"https:\/\/api.slack.com\/scim\/v1\/Users\/WRDCW4CHX"},"userName":"steve","nickName":"steve","name":{"givenName":"Hiroyuki","familyName":"Aoki"},"displayName":"steve","profileUrl":"https:\/\/your-domain.enterprise.slack.com\/team\/Steve Aoki","title":"","timezone":"America\/Los_Angeles","active":true,"emails":[{"value":"saoki@example.com","primary":true}],"photos":[{"value":"https:\/\/secure.gravatar.com\/avatar\/111.jpg","type":"photo"}],"groups":[]},{"schemas":["urn:scim:schemas:core:1.0"],"id":"W0107TELUM7","externalId":"","meta":{"created":"2020-03-22T17:38:28-07:00","location":"https:\/\/api.slack.com\/scim\/v1\/Users\/W0107TELUM7"},"userName":"will.i.am","nickName":"will.i.am","name":{"givenName":"William","familyName":"Adams"},"displayName":"will.i.am","profileUrl":"https:\/\/your-domain.enterprise.slack.com\/team\/will.i.am","title":"","timezone":"America\/Los_Angeles","active":true,"emails":[{"value":"will-i-am@example.com","primary":true}],"photos":[{"value":"https:\/\/secure.gravatar.com\/avatar\/222.jpg","type":"photo"}],"groups":[]}]}>>>users.
users.activeusers.external_idusers.idusers.nameusers.profile_urlusers.start_indexusers.to_dict(users.display_nameusers.from_dict(users.items_per_pageusers.nick_nameusers.resourcesusers.timezoneusers.total_resultsusers.emailsusers.groupsusers.metausers.photosusers.schemasusers.titleusers.user_name

>>>list(map(lambdau:u.id,users.resources))['WRDCW4CHX','W0107TELUM7']>>>list(map(lambdau:u.to_dict()["name"],users.resources))[{'familyName':'Aoki','givenName':'Steve'},{'familyName':'Adams','givenName':'Adams'}]BasicsInstallationpipinstallslack-scimUser Managementhttps://api.slack.com/scim#usersimportosfromslack_scimimportUsers,Userfromslack_scimimportSCIMClient,SCIMApiError# `admin` scope requiredtoken=os.environ["SLACK_ADMIN_TOKEN"]client=SCIMClient(token=token)try:search_result:Users=client.search_users(filter="restricted eq '1'",count=3)user_id=search_result.resources[0].idread_result:User=client.read_user(user_id)exceptSCIMApiErroraserr:iferr.status==429:# handle rate limit errorspassnew_user:User=User.from_dict({"name":{"givenName":"Kazuhiro","familyName":"Sera",},"emails":[{"value":"your-name@example.com"}],"userName":"seratch",})creation_result:User=client.create_user(new_user)user_id=creation_result.idpatch_result:User=client.patch_user(user_id,{"name":{"givenName":"Kaz"}})patch_result.name.given_name="K"update_result:User=client.update_user(user_id,patch_result)client.delete_user(user_id)Group Managementhttps://api.slack.com/scim#groupsimportosfromslack_scimimportGroups,Group,GroupMember,SCIMClient,User# `admin` scope requiredtoken=os.environ["SLACK_ADMIN_TOKEN"]client=SCIMClient(token=token)display_name="test-group-123"new_group:Group=Group.from_dict({"displayName":display_name})created_user:User=client.create_user(User.from_dict({"name":{"givenName":"Kazuhiro","familyName":"Sera",},"emails":[{"value":"your-name@example.com"}],"userName":"seratch",}))new_group.members=[GroupMember.from_dict(created_user.to_dict())]creation_result:Group=client.create_group(new_group)ifnotcreation_result:search_result:Groups=client.search_groups(filter=f"displayName eq{display_name}",count=1)creation_result:Group=search_result.resources[0]group_id=creation_result.idclient.patch_group(group_id,{"displayName":display_name+"-2"})patch_result:Group=client.read_group(group_id)patch_result.display_name=display_name+"-3"client.update_group(group_id,patch_result)update_result=client.read_group(group_id)client.delete_group(group_id)LicenseThe MIT License