{"id":13642519,"url":"https://github.com/JonathanHolvey/sharepy","last_synced_at":"2025-04-20T16:32:41.510Z","repository":{"id":40762902,"uuid":"56773176","full_name":"JonathanHolvey/sharepy","owner":"JonathanHolvey","description":"Simple SharePoint authentication for Python","archived":false,"fork":false,"pushed_at":"2023-09-20T14:17:23.000Z","size":119,"stargazers_count":176,"open_issues_count":37,"forks_count":52,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-14T10:53:40.135Z","etag":null,"topics":["authentication","python","sharepoint-online"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JonathanHolvey.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-21T12:48:33.000Z","updated_at":"2025-03-01T13:40:24.000Z","dependencies_parsed_at":"2024-06-18T16:59:09.686Z","dependency_job_id":"2cda5e84-82bc-4fc6-a659-852b0a6a1039","html_url":"https://github.com/JonathanHolvey/sharepy","commit_stats":{"total_commits":144,"total_committers":6,"mean_commits":24.0,"dds":"0.17361111111111116","last_synced_commit":"982dbdb6031a1cc6dcda4e5bfbca0475026af616"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonathanHolvey%2Fsharepy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonathanHolvey%2Fsharepy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonathanHolvey%2Fsharepy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonathanHolvey%2Fsharepy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JonathanHolvey","download_url":"https://codeload.github.com/JonathanHolvey/sharepy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249926552,"owners_count":21346581,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","python","sharepoint-online"],"created_at":"2024-08-02T01:01:32.525Z","updated_at":"2025-04-20T16:32:41.279Z","avatar_url":"https://github.com/JonathanHolvey.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# SharePy - Simple SharePoint Online authentication for Python\n\nThis module will handle authentication for your SharePoint Online/O365 site, allowing you to make straightforward HTTP requests from Python. It extends the commonly used *Requests* module, meaning that returned objects are familliar, easy to work with and well documented. \n\n## Installation\n\nSharePy can be installed from the Python Package Index, PyPI.\n\n```\npip install sharepy\n```\n\n## Initiating a SharePoint session\n\n```python\nimport sharepy\ns = sharepy.connect(\"example.sharepoint.com\")\n```\n\nYou will be prompted to enter your username and password, which are used to request a security token from Microsoft. An access cookie and request digest token are then retrieved and saved to properties for later use. The digest token will be refreshed automatically as it expires.\n\nA username and password can also be provided as arguments of the `connect` function, if prompts are not desirable.\n\n## Making API calls\n\n```python\nr = s.get(\"https://example.sharepoint.com/_api/web/lists/GetByTitle('Test Library')\")\n```\n\nThis will return a *Requests* `response` object. See the [requests documentation](http://docs.python-requests.org/en/master/) for details. By default, the headers `Accept: application/json; odata=verbose` and `Content-type: application/json; odata=verbose` are sent with all requests, so API responses will be formatted as JSON where available.\n\nHeaders can be added or overridden by supplying a dictionary to the relevant method:\n\n```python\nr = s.get(\"https://example.sharepoint.com/_api/...\", headers={\"Accept\": \"application/atom+xml\"})\n```\n\nThe request will send a digest header, allowing modifications to be made to SharePoint objects.\n\n### Downloading a file\n\n```python\nr = s.getfile(\"https://example.sharepoint.com/Library/Test%20File.pdf\")\n```\n\nThis will download the file to the current directory and return a `response` object. Alternatively you can specify a location to save the file to:\n\n```python\nr = s.getfile(\"https://example.sharepoint.com/Library/Test%20File.pdf\", filename=\"downloads/file.pdf\")\n```\n\n### Uploading a file\n\nSuccessfully uploading a file to SharePoint is a complex task which is described in detail in [issue #4](https://github.com/JonathanHolvey/sharepy/issues/4).\n\nThe actual file upload can be achieved with the following code, where `filepath` is the path to the file to upload, `folder` is the library on the SharePoint server and `filename` is the name to give to the file on upload.\n\n```python\nwith open(filepath, \"rb\") as f:\n    data = f.read()\n\nurl = \"https://example.sharepoint.com/_api/web/GetFolderByServerRelativeUrl('{}')/Files/add(url='{}',overwrite=true)\"\nr = s.post(url.format(folder, filename), data=data, headers={\"content-length\": len(data)})\n```\n\n## Saving an authenticated session\n\nProperties of the authentication session can be saved to a file using the `save` method, so the session can be used without having to re-authenticate each time a program is run:\n\n```python\ns.save()\n```\n\nLater, the `load` function can be used to restore the session:\n\n```python\ns = sharepy.load()\n```\n\nThe default file name for saving and loading sessions is `sp-session.pkl`, however an alternative location can be provided as an argument to `save()` and `load()`.\n\n## Advanced usage\n\n### Requests authentication\n\nSharePy implements Requests authentication classes that can also be used directly with Requests itself:\n\n```python\nimport requests\nimport sharepy\n\nauth = sharepy.auth.SharePointOnline(username=\"user@example.com\")\nauth.login(site=\"example.sharepoint.com\")\nr = requests.get(\"https://example.sharepoint.com\", auth=auth)\n```\n\nAvailable authentication classes are:\n\n- `SharepointOnline` - For normal SharePoint Online sites\n- `SharepointADFS` - For ADFS-enabled sites\n\n### Custom authentication URL\n\nThe authentication URL is detected automatically when using `sharepy.connect()`. If a different URL is required for a region-specific account, it can be specified by manually creating an auth object and setting its `login_url` property:\n\n```python\nimport sharepy\n\nauth = sharepy.auth.SharePointOnline(username=\"user@example.com\")\nauth.login_url = \"https://login.microsoftonline.de/extSES.srf\"\ns = sharepy.SharePointSession(\"example.sharepoint.com\", auth)\n```\n\n## Useful reading\n\n- Constructing SharePoint API calls: [SharePoint REST API documentation](https://msdn.microsoft.com/en-us/library/office/dn292552.aspx)\n- Handling JSON objects in Python: [Python JSON module documentation](https://docs.python.org/3.4/library/json.html)\n\n## Licence\n\nThis software is distributed under the GNU General Public License v3. Copyright 2016-2021 Jonathan Holvey.\n\n## Credits\n\n1. The authentication method used here is based on [this post](https://allthatjs.com/2012/03/28/remote-authentication-in-sharepoint-online/) by Luc Stakenborg.\n2. Additional help regarding request digests from sadegh's comment on [this post](http://paulryan.com.au/2014/spo-remote-authentication-rest/) by Paul Ryan.\n3. Contributed code from @joemeneses for ADFS authentication.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJonathanHolvey%2Fsharepy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJonathanHolvey%2Fsharepy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJonathanHolvey%2Fsharepy/lists"}