Skip to main content

Installation

$ pip install sharepointcli

Configuration

To allow authentication you first need to register your application. For steps on how to configure the app in the Azure portal, see Register your app

For general use, the spo configure command is the fastest way to set up SharePoint CLI. When you enter this command, the CLI prompts you for the following configurations:

  • SharePoint domain
  • Application (client) ID
  • Application (client) secret

The spo configure command stores the credentials in the credentials file. You can configure configure multiple credentials for different SharePoint domains. Example:

$ spo configure
SharePoint domain (e.g. example.sharepoint.com):
Tenant Id: db3fe96d-1b57-4119-a5fd-bd139021158d
Client Id: fa3ecc92-5994-475e-a647-1f81931aac43
Client Secret: ~vaXZkx&836mH56FymE6Gx7j$t&JT.-5em
Visit the following url to give consent:
https://login.microsoftonline.com/db3fe96d-1b57-4119-a5fd-bd139021158d/oauth2/v2.0/authorize?response_type=...
Paste the authenticated url here:
https://login.microsoftonline.com/common/oauth2/nativeclient?code=....
Authentication Flow Completed. Oauth Access Token Stored. You can now use the API.
Authenticated!

The credentials take precedence in the following order:

  1. Command line options
  2. Environment variables
  3. Credentials file

Command line options

You can use the following command line options to override the default configuration settings.

  • --client_id

    Specifies the Client Id.

  • --client_secret

    Specifies the Client Secret

  • --tenant_id

    Specifies the Tenant Id

Environment variables

Environment variables provide another way to specify credentials, and can be useful for scripting. If you specify an option by using a parameter on the command line, it overrides any value from the environment variables or the configuration file.

The CLI supports the following environment variables:

  • SPO_HOME

    Specifies the home directory. The default path is "~/.spo".

  • SPO_CREDENTIALS_FILE

    Specifies the location of the file that the CLI to store credentials. The default path is "~/.spo/credentials".

  • SPO_CLIENT_ID

    Specifies the Client Id.

  • SPO_CLIENT_SECRET

    Specifies the Client Secret

  • SPO_TENANT_ID

    Specifies the Tenant Id

Credentials file

The CLI stores sensitive credential information in a file named credentials in a directory named .spo in your home directory. For example, the file generated with spo configure looks similar to the following:

[example.sharepoint.com]
client_id = fa3ecc92-5994-475e-a647-1f81931aac43
client_secret = ~vaXZkx&836mH56FymE6Gx7j$t&JT.-5em
tenant_id = db3fe96d-1b57-4119-a5fd-bd139021158d

Usage

authenticate

Performs the OAuth authentication flow using the console.

Usage

$ spo authenticate [domain]

configure

Configures credentials.

Usage

$ spo configure [domain]

cp

Copying a local file to SharePoint.

Usage

$ spo cp <LocalPath> <SharePointUrl>   or   cp <SharePointUrl> <LocalPath>

Examples

The following cp command copies a single file to a specified site:

$ spo cp test.txt 'https://example.sharepoint.com/sites/example/Shared documents/test.txt'
upload: test.txt to https://example.sharepoint.com/sites/example/Shared documents/test.txt

The following cp command copies a single file from a SharePoint site:

$ spo cp 'https://example.sharepoint.com/sites/example/Shared documents/test.txt' test.txt
download: https://example.sharepoint.com/sites/example/Shared documents/test.txt' to test.txt

help

Displays commands help.

Usage

$ spo help [topic]

ls

Lists files and folders.

Usage

$ spo ls [options] <SharePointUrl>
Options

-mtime n File's status was last changed n*24 hours ago. ('+n' more than n, 'n' exactly n, '-n' less than n)

Examples

$ spo ls 'https://example.sharepoint.com/sites/example/Shared documents/*.txt'

mkdir

Creates folder.

Usage

$ spo mkdir <SharePointUrl>

rm

Deletes files.

Usage

$ spo rm [options] <SharePointUrl>
Options

-mtime n File's status was last changed n*24 hours ago. ('+n' more than n, 'n' exactly n, '-n' less than n)

Examples

$ spo rm 'https://example.sharepoint.com/sites/example/Shared documents/*.txt'

rmdir

Deletes folder.

Usage

$ spo rmdir <SharePointUrl>

version

Prints the version number.

Usage

$ spo version

Tests

To run the unit tests:

  • create the ~/.spo/credentials credentials file
  • export your SharePoint test site url as environment variable 'SITE'
$ spo configure
SharePoint domain (e.g. example.sharepoint.com):
Tenant Id: db3fe96d-1b57-4119-a5fd-bd139021158d
Client Id: fa3ecc92-5994-475e-a647-1f81931aac43
Client Secret: ~vaXZkx&836mH56FymE6Gx7j$t&JT.-5em
$ expot SITE='https://example.sharepoint.com/sites/example/Shared documents/test folder'
$ make test

License

This project is licensed under the MIT license.

Metadata

Release files for sharepointcli 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sharepointcli 2.1.0
File Size Uploaded
sharepointcli-2.1.0.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sharepointcli 2.1.0
File Interpreter ABI Platform
sharepointcli-2.1.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 26.7 kB

Release files / sharepointcli-2.1.0.tar.gz

Download URL sharepointcli-2.1.0.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b217724b514d7013ddce34261ece09ac0fb2fe380afbe78b0ebce99a329a4a36
BLAKE2b-256 checksum
How to use checksums
7a67acd89464d4dec51da8012e524d11fc2a6d880dd66350b7a5f9905a1cfdc1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/2.7.18

Release files / sharepointcli-2.1.0-py2.py3-none-any.whl

Download URL sharepointcli-2.1.0-py2.py3-none-any.whl
Size 12.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
fc1ba6f9f029ae89f91515e7e132bbc5f8892796dcf24a0268263961d963785b
BLAKE2b-256 checksum
How to use checksums
067df9082739e03a3927733513bf8c81e5c07f634959cf5f1f581c29e67e6617
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/2.7.18

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.3.1

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page