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)
Metadata
Release files for swydo 1.2019.5.26
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| swydo-1.2019.5.26.tar.gz | 14.7 kB | Without provenance | Details for swydo-1.2019.5.26.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swydo-1.2019.5.26-py3-none-any.whl | Python 3 | none | any | Details for swydo-1.2019.5.26-py3-none-any.whl |
Total release size: 27.1 kB
Release files / swydo-1.2019.5.26.tar.gz
| Download URL | swydo-1.2019.5.26.tar.gz |
|---|---|
| Size | 14.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
59408dfbe7e13ef685bac6a3c15f3187040b564382edd58041f7c760cab76592
|
|
BLAKE2b-256 checksum How to use checksums |
a9fa93f045e43b5b90faca8150b7c6a177e1966a521349a2d6392ed678bdc99c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / swydo-1.2019.5.26-py3-none-any.whl
| Download URL | swydo-1.2019.5.26-py3-none-any.whl |
|---|---|
| Size | 12.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bc6c31df5f78b2abda28d351a044d7ffb1b2f2dde6b28a8521a493d6b50c0e38
|
|
BLAKE2b-256 checksum How to use checksums |
206a569446a0199ddcdfc4e808c2151f9bd1c907f1556f0c63b523fd35b5e310
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for swydo 1.2019.5.26
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.