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
Release history Release notifications | RSS feed
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.22.tar.gz
(5.2 kB
view details)
Built Distribution
File details
Details for the file pySSRSapi-0.0.22.tar.gz
.
File metadata
- Download URL: pySSRSapi-0.0.22.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bba9db9e0e32ea0aecc9040c76408869eb4cc1dd09cb96a5e5fc4a08295cc90 |
|
MD5 | 6b90129d41b68027874facfb81f5e350 |
|
BLAKE2b-256 | b4f0cff2c5887cb3df4b11bebe2f415d647f64f10ad6d340228b8d640890335e |
File details
Details for the file pySSRSapi-0.0.22-py3-none-any.whl
.
File metadata
- Download URL: pySSRSapi-0.0.22-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | de2a38e26b6fc5b826fe32d2beb64375c8c160cf7a2fe8e54ae808cf1bacc842 |
|
MD5 | f295a8a6e8459b0212e2a174fc611b40 |
|
BLAKE2b-256 | 8739a740857202a5e45bcdcdcdb9b56bc49570f78e46b072e9c572c68b76b3ca |