Shep Sims
Shep Sims

Reputation: 1560

When using the python azure-devops package, how can I authenticate with a PAT?

The Microsoft Azure-DevOps package on GitHub provides a single use-case for using their library on the READ-ME page as such

from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
import pprint

# Fill in with your personal access token and org URL
personal_access_token = 'YOURPAT'
organization_url = 'https://dev.azure.com/YOURORG'

# Create a connection to the org
credentials = BasicAuthentication('', personal_access_token)
connection = Connection(base_url=organization_url, creds=credentials)

# Get a client (the "core" client provides access to projects, teams, etc)
core_client = connection.clients.get_core_client()

# Get the list of projects in the org
projects = core_client.get_projects()

# Show details about each project in the console
for project in projects:
    pprint.pprint(project.__dict__)

I have looked around online and have found no documentation or way to figure out how to install or use the "mrest.authentication" import and as such cannot create a connection to Azure-DevOps or use this library at all.

using pip install mrest says that there are no matching packages found online, and I cannot figure out why Microsoft would include this in documentation if it is a private library.

If anyone knows a workaround for creating a connection with the azure-DevOps package, how to install the mrest package or a better way to access the Azure DevOps REST API please let me know, thanks all!

Upvotes: 2

Views: 1939

Answers (2)

Patrick Dassier
Patrick Dassier

Reputation: 21

You need to install msrest package, not mrest: pip3 install msrest

Upvotes: 2

Rajendra Adhikari
Rajendra Adhikari

Reputation: 36

you will need: pip install azure-devops

Upvotes: 2

Related Questions