Swydo Python SDK (swydo)
Project description
swydo
A Python 3 module to interact with the Swydo API.
Developed in Mayple.
Install
pip install swydo
Example
import logging
import swydo
import itertools
from bravado.exception import HTTPError
logging.basicConfig()
YOUR_API_KEY="..."
# Manually injected, as Swydo sometimes doesn't return teams
yourTeamId = "..."
print("Starting...")
swydoClient = swydo.SwydoClient(apiKey=YOUR_API_KEY, autoRetry=True)
yourBrandTemplateId = "..."
yourReportTemplateId = "..."
yourFacebookAdsConnectionId = "..."
yourFacebookGraphConnectionId = "..."
yourGoogleAdWordsConnectionId = "..."
yourGoogleAnalyticsConnectionId = "..."
# If you have one
testClientId = ""
skipInitialEnumeration = False
if not skipInitialEnumeration:
teams = list(swydoClient.getTeams())
for teamId in itertools.chain(
(team['id'] for team in teams),
[yourTeamId]
):
team = swydoClient.getTeam(teamId)
assert team['id'] == teamId
print("Team: %s" % team)
teamUsers = swydoClient.getTeamUsers(teamId=teamId)
for userId in (user['id'] for user in teamUsers):
user = swydoClient.getTeamUser(teamId=teamId, userId=userId)
assert userId == user['id']
print("User: %s" % user)
teamConnections = swydoClient.getTeamConnections(teamId=teamId)
for connectionId in (connection['id'] for connection in teamConnections):
connection = swydoClient.getTeamConnection(teamId=teamId, connectionId=connectionId)
assert connectionId == connection['id']
print("Connection: %s" % connection)
teamBrandTemplates = swydoClient.getTeamBrandTemplates(teamId=teamId)
for brandTemplateId in (brandTemplate['id'] for brandTemplate in teamBrandTemplates):
brandTemplate = swydoClient.getTeamBrandTemplate(teamId=teamId, brandTemplateId=brandTemplateId)
assert brandTemplateId == brandTemplate['id']
print("BrandTemplate: %s" % brandTemplate)
teamReportTemplates = swydoClient.getTeamReportTemplates(teamId=teamId)
for reportTemplateId in (reportTemplate['id'] for reportTemplate in teamReportTemplates):
reportTemplate = swydoClient.getTeamReportTemplate(teamId=teamId, reportTemplateId=reportTemplateId)
assert reportTemplateId == reportTemplate['id']
print("ReportTemplate: %s" % reportTemplate)
teamClients = swydoClient.getTeamClients(teamId=teamId)
for clientId in (client['id'] for client in teamClients):
client = swydoClient.getTeamClient(teamId=teamId, clientId=clientId)
assert clientId == client['id']
print("Client: %s" % client)
clientDataSources = swydoClient.getClientDataSources(teamId=teamId, clientId=clientId)
assert clientId == clientDataSources['id']
print("ClientDataSources: %s" % clientDataSources)
teamReports = swydoClient.getTeamReports(teamId=teamId)
for reportId in (report['id'] for report in teamReports):
report = swydoClient.getTeamReport(teamId=teamId, reportId=reportId)
assert reportId == report['id']
print("Report: %s" % report)
# Find a specific client
try:
testClient = swydoClient.getTeamClient(teamId=yourTeamId, clientId=testClientId)
except HTTPError as he:
if he.status_code == 404:
testClient = None
else:
raise
if not testClient:
testClient = swydoClient.createTeamClient(
teamId=yourTeamId,
name="Test Client via API",
description="Test Client's Description",
email="test@email.com"
)
print("Test Client: %s" % testClient)
testClient = swydoClient.updateTeamClient(
teamId=yourTeamId,
clientId=testClient['id'],
name="Updated Test Client via API",
description="Updated Test Client's Description",
)
print("Test Client: %s" % testClient)
swydoClient.archiveTeamClient(
teamId=yourTeamId,
clientId=testClient['id'],
)
print("Test Client archived.")
swydoClient.unarchiveTeamClient(
teamId=yourTeamId,
clientId=testClient['id'],
)
print("Test Client unarchived.")
swydoClient.removeClientDataSourceFacebookAds(
teamId=yourTeamId,
clientId=testClientId,
)
print("facebookAdsDataSource removed")
swydoClient.removeClientDataSourceFacebookGraph(
teamId=yourTeamId,
clientId=testClientId,
)
print("FacebookGraph DataSource removed")
swydoClient.removeClientDataSourceGoogleAdWords(
teamId=yourTeamId,
clientId=testClientId,
)
print("GoogleAdWords DataSource removed")
swydoClient.removeClientDataSourceGoogleAnalytics(
teamId=yourTeamId,
clientId=testClientId,
)
print("GoogleAnalytics DataSource removed")
# FacebookAds
facebookAdsDataSource = swydoClient.setClientDataSourceFacebookAds(
teamId=yourTeamId,
clientId=testClientId,
connectionId=yourFacebookAdsConnectionId,
dataSourceId='adAccountId',
dataSourceName='Added Facebook Ad Account',
dataSourceCurrencyCode='USD',
)
print("FacebookAds DataSource: %s" % facebookAdsDataSource)
# FacebookGraph
facebookGraphDataSource = swydoClient.setClientDataSourceFacebookGraph(
teamId=yourTeamId,
clientId=testClientId,
connectionId=yourFacebookGraphConnectionId,
dataSourceId='dataSourceId',
dataSourceName='Added Facebook Graph Account',
dataSourcePageId='dataSourcePageId',
)
print("FacebookGraph DataSource: %s" % facebookGraphDataSource)
# GoogleAdWords
googleAdWordsDataSource = swydoClient.setClientDataSourceGoogleAdWords(
teamId=yourTeamId,
clientId=testClientId,
connectionId=yourGoogleAdWordsConnectionId,
dataSourceClientId='dataSourceClientId',
dataSourceName='Added Google Ads Account',
dataSourceCurrencyCode='USD',
)
print("GoogleAdWords DataSource: %s" % googleAdWordsDataSource)
# GoogleAnalytics
googleAnalyticsDataSource = swydoClient.setClientDataSourceGoogleAnalytics(
teamId=yourTeamId,
clientId=testClientId,
connectionId=yourGoogleAnalyticsConnectionId,
dataSourceAccountId='dataSourceAccountId',
dataSourceName='Added Google Analytics Account',
dataSourceAccountName='dataSourceAccountName',
dataSourceWebPropertyId='dataSourceWebPropertyId',
dataSourceProfileId='dataSourceProfileId',
dataSourceCurrencyCode='USD',
)
print("GoogleAnalytics DataSource: %s" % googleAnalyticsDataSource)
# Create a report
testReport = swydoClient.createTeamReport(
teamId=yourTeamId,
name="Temporary Report",
clientId=testClientId,
brandTemplateId=yourBrandTemplateId,
reportTemplateId=yourReportTemplateId,
comparePeriod=swydo.Enumerations.ComparePeriod.previous,
)
print("TestReport: %s" % testReport)
testReportId = testReport['id']
# Share the report
swydoClient.shareTeamReport(
teamId=yourTeamId,
reportId=testReportId,
)
# Update the report
testReport = swydoClient.updateTeamReport(
teamId=yourTeamId,
reportId=testReportId,
name="Temporary Report Updated",
)
print("TestReport: %s" % testReport)
testReportId = testReport['id']
# Unshare the report
swydoClient.unshareTeamReport(
teamId=yourTeamId,
reportId=testReportId,
)
# Delete the report
swydoClient.deleteTeamReport(
teamId=yourTeamId,
reportId=testReportId,
)
swydoClient.removeClientDataSourceFacebookAds(
teamId=yourTeamId,
clientId=testClientId,
)
print("facebookAdsDataSource removed")
swydoClient.removeClientDataSourceFacebookGraph(
teamId=yourTeamId,
clientId=testClientId,
)
print("FacebookGraph DataSource removed")
swydoClient.removeClientDataSourceGoogleAdWords(
teamId=yourTeamId,
clientId=testClientId,
)
print("GoogleAdWords DataSource removed")
swydoClient.removeClientDataSourceGoogleAnalytics(
teamId=yourTeamId,
clientId=testClientId,
)
print("GoogleAnalytics DataSource removed")
print("Success!...")
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Install with:
$ virtualenv .venv -p python3
$ . .venv/bin/activate
(.venv) $ pip install -r requirements.txt
and run the tests with:
(.venv) $ pip install -r tests/requirements.txt
(.venv) $ pytest tests/
documentation can be generated like this:
(.venv) $ pip install -r doc/requirements.txt
(.venv) $ sphinx-build -b html doc doc/_build/html
Related Projects
Used cookiecutter Python library template by mdklatt.
Author
Alon Diamant (advance512)
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
swydo-1.2019.5.26.tar.gz
(14.7 kB
view details)
Built Distribution
File details
Details for the file swydo-1.2019.5.26.tar.gz
.
File metadata
- Download URL: swydo-1.2019.5.26.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.9.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59408dfbe7e13ef685bac6a3c15f3187040b564382edd58041f7c760cab76592 |
|
MD5 | ac9d2772355e7bff43743ee51a63cbcb |
|
BLAKE2b-256 | a9fa93f045e43b5b90faca8150b7c6a177e1966a521349a2d6392ed678bdc99c |
File details
Details for the file swydo-1.2019.5.26-py3-none-any.whl
.
File metadata
- Download URL: swydo-1.2019.5.26-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.9.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc6c31df5f78b2abda28d351a044d7ffb1b2f2dde6b28a8521a493d6b50c0e38 |
|
MD5 | 582e504db3535add38896b3aeec5bb24 |
|
BLAKE2b-256 | 206a569446a0199ddcdfc4e808c2151f9bd1c907f1556f0c63b523fd35b5e310 |