Skip to main content

Python SSRS API

Project description

Python SSRS API

Python implementation of the SSRS API that allows to list, add, edit, delete folders, datasources and reports on an SSRS server.


Initiate api with basic auth

import pySSRSapi

# basic auth
api = pySSRSapi.Api(
    url = 'http://localhost/Reports/api/v2.0',
    user = 'username',
    password = 'password'
)

User

Get current user

user = api.getUser()

System

Get system info

system = api.getSystem()

Folders

Get folders

# list folders
folders = api.getFolders()

# get folder by id
folder = api.getFolderById(id='00000000-0000-0000-0000-000000000000')

# get folder by path
folder = api.getFolderByPath(path='/folder1')

# get root folder
folder = api.getRootFolder()

Add folder

# get root folder for parent folder id
rootFolder = api.getRootFolder()

# initiate new folder
newFolder = pySSRSapi.Folder(
    Id=None,
    Name='folder1',
    Description='Description folder 1',
    Path='/folder1',
    ParentFolderId=rootFolder.Id
)

# add new folder
addedFolder = api.addFolder(folder=newFolder)

Edit folder

# get folder to edit
folder = api.getFolderByPath(path='/folder1')

# modify values
folder.Description = 'Folder 1 desc'

# edit folder
editedFolder = api.editFolder(id=folder.Id, folder=folder)

Set folder policies

# get folder
folder = api.getFolderByPath(path='/folder1')

# initiate policies
policies = dict(
    InheritParentPolicy=False,
    Policies=[
        dict(
            GroupUserName='SERVER\\user_ssrs_1',
            Roles=[
                dict(
                    Name='Report Builder',
                    Description=None
                )
            ]
        )
    ]
)

# set folder policies
api.setFolderPolicies(id=folder.Id, policies=policies)

Delete folder

# get folder to edit
folder = api.getFolderByPath(path='/folder1')

# delete folder
api.deleteFolder(id=folder.Id)

Datasources

Get datatources

# list datasources
datasources = api.getDatasources()

# get datasource by id
datasource = api.getDatasourceById(id='00000000-0000-0000-0000-000000000000')

# get datasource by path
datasource = api.getDatasourceByPath(path='/folder1/datasource1')

Add datasource

# get folder to edit
folder = api.getFolderByPath(path='/folder1')

# get rds file in b64 json friendly
with open('datasource1.rds', 'rb') as f:
    byte_content = f.read()
base64_bytes = base64.b64encode(byte_content)
file_content = base64_bytes.decode('utf-8')

# initiate new datasource
newDatasource = pySSRSapi.Datasource(
    Id=None,
    Name='datasource1',
    Description='Description datasource 1',
    Path='/folder1/datasource1',
    ParentFolderId=folder.Id,
    DataSourceType='ODBC',
    ConnectionString='Dsn=DATASOURCE_1_ODBC_CONNECTION',
    Content=file_content
)

# add new datasource
addedDatasource = api.addDatasource(datasource=newDatasource)

Edit datasource

# get datasource to edit
datasource = api.getDatasourceByPath(path='/folder1/datasource1')

# modify values
datasource.Description = 'Datasource 1 desc'

# edit datasource
editedDatasource = api.editDatasource(id=datasource.Id, datasource=datasource)

Set datasource policies

# get datasource
datasource = api.getDatasourceByPath(path='/folder1/datasource1')

# initiate policies
policies = dict(
    InheritParentPolicy=False,
    Policies=[
        dict(
            GroupUserName='SERVER\\user_ssrs_1',
            Roles=[
                dict(
                    Name='Report Builder',
                    Description=None
                )
            ]
        )
    ]
)

# set datasource policies
api.setDatasourcePolicies(id=datasource.Id, policies=policies)

Delete datasource

# get datasource to edit
datasource = api.getDatasourceByPath(path='/folder1/datasource1')

# delete datasource
api.deleteDatasource(id=datasource.Id)

Reports

Get reports

# list reports
reports = api.getReports()

# get report by id
report = api.getReportById(id='00000000-0000-0000-0000-000000000000')

# get report by path
report = api.getReportByPath(path='/folder1/report1')

Add report

# get folder to edit
folder = api.getFolderByPath(path='/folder1')

# get rds file in b64 json friendly
with open('report1.rdl', 'rb') as f:
    byte_content = f.read()
base64_bytes = base64.b64encode(byte_content)
file_content = base64_bytes.decode('utf-8')

# initiate new report
newReport = pySSRSapi.Report(
    Id=None,
    Name='report1',
    Description='Description report 1',
    Path='/folder1/report1',
    ParentFolderId=folder.Id,
    Content=file_content
)

# add new report
addedReport = api.addReport(report=newReport)

Edit report

# get report to edit
report = api.getReportByPath(path='/folder1/report1')

# modify values
report.Description = 'Report 1 desc'

# edit report
editedReport = api.editReport(id=report.Id, datasource=report)

Set report policies

# get report
report = api.getReportByPath(path='/folder1/report1')

# initiate policies
policies = dict(
    InheritParentPolicy=False,
    Policies=[
        dict(
            GroupUserName='SERVER\\user_ssrs_1',
            Roles=[
                dict(
                    Name='Report Builder',
                    Description=None
                )
            ]
        )
    ]
)

# set report policies
api.setReportPolicies(id=report.Id, policies=policies)

Delete report

# get report to edit
report = api.getReportByPath(path='/folder1/report1')

# delete report
api.deleteReport(id=report.Id)

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

pySSRSapi-0.0.21.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

pySSRSapi-0.0.21-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file pySSRSapi-0.0.21.tar.gz.

File metadata

  • Download URL: pySSRSapi-0.0.21.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for pySSRSapi-0.0.21.tar.gz
Algorithm Hash digest
SHA256 177ecbb39daa622d050e0fd455c1fb0a77567917c9135372e314121722abfc09
MD5 5153f2510be443b0897017bca4a1f04f
BLAKE2b-256 978fa5945c2f270af73654762df51acfcb25b4940a5e553942027dddab37fe3e

See more details on using hashes here.

File details

Details for the file pySSRSapi-0.0.21-py3-none-any.whl.

File metadata

  • Download URL: pySSRSapi-0.0.21-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for pySSRSapi-0.0.21-py3-none-any.whl
Algorithm Hash digest
SHA256 24f0167f189f920a9cb93f46f4c35d7213316be95f0aeeff315f46c4a5e97ffa
MD5 b2835d5862a03b131cacb9e0da453cc4
BLAKE2b-256 ef2ba9dfc446c7846acbcee1d8e0348d1ccd6d4ffb14cd887b5eaa5f18d51e8d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page