Python package that acts as a wrapper for the Microsoft Graph API.
Project description
grafap
grafap (graph-wrap) is a Python package for interacting with the Microsoft Graph API, primarily sharepoint lists. Creating new items, querying lists, etc.
Installation
pip install grafap
Usage
Several environment variables are required for grafap to function. Most of the endpoints in grafap are just using the standard Microsoft Graph API which only requires a client ID and secret. The Sharepoint REST API, however requires using a client certificate. At least for the only endpoint being used thus far "ensure user".
MS Graph Env Vars
Required? | Env Variable | Description |
---|---|---|
Yes | GRAPH_LOGIN_BASE_URL | Should be https://login.microsoftonline.com/ |
Yes | GRAPH_BASE_URL | Should be https://graph.microsoft.com/v1.0/sites/ |
Yes | GRAPH_TENANT_ID | Tenant ID from app registration created in Azure. |
Yes | GRAPH_CLIENT_ID | Client ID from app registration created in Azure. |
Yes | GRAPH_CLIENT_SECRET | Client secret from app registration created in Azure. |
Yes | GRAPH_GRANT_TYPE | Should be 'client_credentials' |
Yes | GRAPH_SCOPES | Should typically be https://graph.microsoft.com/.default unless using more fine-grained permissions. |
Sharepoint Rest API Env Vars
Required? | Env Variable | Description |
---|---|---|
No | SP_SITE | Base Site URL you're interacting with. Should be https://DOMAIN.sharepoint.com/ |
No | SP_SCOPES | Scopes for sharepoint rest API. Should look like <https://{tenant name}.sharepoint.com/.default> |
No | SP_LOGIN_BASE_URL | Should be https://login.microsoftonline.com/ |
No | SP_TENANT_ID | Tenant ID from app registration created in Azure. |
No | SP_CLIENT_ID | Client ID from app registration created in Azure. |
No | SP_GRANT_TYPE | client_credentials |
No | SP_CERTIFICATE_PATH | Path to .pfx file |
No | SP_CERTIFICATE_PASSWORD | Password for the .pfx file. |
Sites
Get SharePoint Sites
Gets all SharePoint sites in the tenant.
Lists
Get SharePoint Lists
Gets all SharePoint lists in a site. Takes one parameter:
site_id - ID for the given site.
Get SharePoint List Items
Gets all items in a sharepoint list. Takes 2 required parameters and 1 optional.
site_id - ID for which site list is in list_id - ID for the list being queried filter_query - Optional OData filter query, e.g. "Department eq 1234"
Note: If you're using the filter_query expression, whichever field you want to filter on needs to be indexed or you'll get an error. To index a column, just add it in the sharepoint list settings.
Create SharePoint List Item
Creates a new item in a given sharepoint list. Takes three parameters:
site_id - long string with three components separated by commas. Starts with SP site URL (DOMAIN.sharepoint.com) list_id - Unique ID for the given list you want to add an item to. Use the get_sp_lists function to get the IDs for all lists in a site. field_data - Dictionary of fields you are populating. Formatted like below.
{
"FieldName": "FieldValue",
"Field2Name": true
}
Update SharePoint List Item
Updates one or more fields of a particular item in a list. Formatted almost identically to create item function, but only including fields whose values are being updated, as well as additional item ID parameter. Takes four parameters:
site_id - long string with three components separated by commas. Starts with SP site URL (DOMAIN.sharepoint.com) list_id - Unique ID for the given list you want to update item on. Use the get_sp_lists function to get the IDs for all lists in a site. item_id - ID of the list item being updated field_data - Dictionary of fields you are updating. Formatted like below.
{
"FieldName": "FieldValue",
"Field2Name": true
}
OneNote
Not yet implemented.
Term Store
Get Termstore Groups
Lists all termstore group objects in a site
site_id - ID for which site list is in, can be 'root'
Users
Get Users
Returns list of Azure AD users.
Get all SharePoint User's Info
Queries hidden User Information List. Returns info for all users in a site.
site_id - ID for which site list is in, can be 'root'
Get a Sharepoint User's Info
Queries hidden User Information List. Returns info for a specific user ID.
site_id - ID for which site list is in, can be 'root' user_id - ID of the list item being queried
Ensure SharePoint User
"Ensures" a user for a given sharepoint site. Sharepoint doesn't, by default, have all users in a sharepoint tenant in each site you have. They have to interact with it in some way or you need to pick them on a Person field. So there's no way to programmatically set a user if they aren't already in the hidden Sharepoint User Information List in the site. Ensuring a user is essentially doing that, putting them in the list. The endpoint is not available in the MS Graph API, because Microsoft. So we need to use the SharePoint REST API for this.
site_url - Base URL of the sharepoint site logon_name - Email of the user you want to ensure
Get all Sharepoint Users' Info
Queries hidden User Information List SP list. Returns all user info so can be associated with lookup values.
site_id - ID for which site list is in, can be 'root'
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file grafap-0.1.4.tar.gz
.
File metadata
- Download URL: grafap-0.1.4.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bfc45c555f058ba9ef90abd22b3c9a8747153423eb59e91a9fa3496944fed53 |
|
MD5 | 217d4d134955425cf20114a9841175a9 |
|
BLAKE2b-256 | f89c56d56d05dfa22ba488ce63c8c50e9490ecfbf62bb803011046093ef2d27a |
File details
Details for the file grafap-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: grafap-0.1.4-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81b300f580b19d5c5dc968b87dd9354d89a98c5a139b935b52c4e3ddb644d562 |
|
MD5 | d350fc427026de646c218fc39e996372 |
|
BLAKE2b-256 | 282054839a110f6bc8b84aa23a895e73e057468efe7ce9db19a06891053cbee3 |