sharepy


Namesharepy JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/JonathanHolvey/sharepy
SummarySimple SharePoint Online authentication for Python
upload_time2022-02-05 05:13:42
maintainer
docs_urlNone
authorJonathan Holvey
requires_python>=3.6, <4
licenseGPLv3
keywords sharepoint online authentication
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SharePy - Simple SharePoint Online authentication for Python

This 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. 

## Installation

SharePy can be installed from the Python Package Index, PyPI.

```
pip install sharepy
```

## Initiating a SharePoint session

```python
import sharepy
s = sharepy.connect("example.sharepoint.com")
```

You 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.

A username and password can also be provided as arguments of the `connect` function, if prompts are not desirable.

## Making API calls

```python
r = s.get("https://example.sharepoint.com/_api/web/lists/GetByTitle('Test Library')")
```

This 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.

Headers can be added or overridden by supplying a dictionary to the relevant method:

```python
r = s.get("https://example.sharepoint.com/_api/...", headers={"Accept": "application/atom+xml"})
```

The request will send a digest header, allowing modifications to be made to SharePoint objects.

### Downloading a file

```python
r = s.getfile("https://example.sharepoint.com/Library/Test%20File.pdf")
```

This will download the file to the current directory and return a `response` object. Alternatively you can specify a location to save the file to:

```python
r = s.getfile("https://example.sharepoint.com/Library/Test%20File.pdf", filename="downloads/file.pdf")
```

## Saving an authenticated session

Properties 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:

```python
s.save()
```

Later, the `load` function can be used to restore the session:

```python
s = sharepy.load()
```

The 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()`.

## Advanced usage

### Requests authentication

SharePy implements Requests authentication classes that can also be used directly with Requests itself:

```python
import requests
import sharepy

auth = sharepy.auth.SharePointOnline(username="user@example.com")
auth.login(site="example.sharepoint.com")
r = requests.get("https://example.sharepoint.com", auth=auth)
```

Available authentication classes are:

- `SharepointOnline` - For normal SharePoint Online sites
- `SharepointADFS` - For ADFS-enabled sites

### Custom authentication URL

The 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:

```python
import sharepy

auth = sharepy.auth.SharePointOnline(username="user@example.com")
auth.login_url = "https://login.microsoftonline.de/extSES.srf"
s = sharepy.SharePointSession("example.sharepoint.com", auth)
```

## Useful reading

- Constructing SharePoint API calls: [SharePoint REST API documentation](https://msdn.microsoft.com/en-us/library/office/dn292552.aspx)
- Handling JSON objects in Python: [Python JSON module documentation](https://docs.python.org/3.4/library/json.html)

## Licence

This software is distributed under the GNU General Public License v3. Copyright 2016-2021 Jonathan Holvey.

## Credits

1. The authentication method used here is based on [this post](https://allthatjs.com/2012/03/28/remote-authentication-in-sharepoint-online/) by Luc Stakenborg.
2. Additional help regarding request digests from sadegh's comment on [this post](http://paulryan.com.au/2014/spo-remote-authentication-rest/) by Paul Ryan.
3. Contributed code from @joemeneses for ADFS authentication.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/JonathanHolvey/sharepy",
    "name": "sharepy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6, <4",
    "maintainer_email": "",
    "keywords": "sharepoint online authentication",
    "author": "Jonathan Holvey",
    "author_email": "jonathan.holvey@outlook.com",
    "download_url": "https://files.pythonhosted.org/packages/39/de/f27c086bce54884a8538a22878ebf9e3a803a66c27b5d604d02538d93b30/sharepy-2.0.0.tar.gz",
    "platform": "",
    "description": "# 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## 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\n\n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "Simple SharePoint Online authentication for Python",
    "version": "2.0.0",
    "split_keywords": [
        "sharepoint",
        "online",
        "authentication"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "39def27c086bce54884a8538a22878ebf9e3a803a66c27b5d604d02538d93b30",
                "md5": "84c5588b89067bc4bb86cd79e4b8555b",
                "sha256": "683ba3d472b9dfa259e01f3b9e8a4aea3abc833fb01ca2ca1c22e618301ded1a"
            },
            "downloads": -1,
            "filename": "sharepy-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "84c5588b89067bc4bb86cd79e4b8555b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6, <4",
            "size": 23186,
            "upload_time": "2022-02-05T05:13:42",
            "upload_time_iso_8601": "2022-02-05T05:13:42.466181Z",
            "url": "https://files.pythonhosted.org/packages/39/de/f27c086bce54884a8538a22878ebf9e3a803a66c27b5d604d02538d93b30/sharepy-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-02-05 05:13:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "JonathanHolvey",
    "github_project": "sharepy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "sharepy"
}
        
Elapsed time: 0.04329s