Friday, November 12, 2021

Python — Extract Data from Salesforce Marketing Cloud (ExactTarget)

As we know that data is truly the new diamond in the rough and accelerated digital technologies have initiated new business models and revenue streams.  Salesforce Marketing Cloud Email Studio helps us to get the best ROI from email marketing which  lets us to create targeted one-to-one email communications at scale, with end-to-end campaign development and sophisticated content delivery capabilities. 

Python — Extract Data from Salesforce Marketing Cloud (ExactTarget)
Salesforce Marketing Cloud (SFMC) is Salesforce’s SaaS platform which is highly capable to is a provider of digital marketing automation and analytics software and services. SFMC is a marketing platform that has capabilities capabilities across the marketing domain to support many facets of marketing including multi-channel campaign execution, dynamic customer journeys, pre- and post-campaign analytics including audience building and segmentation, social media engagement and advertising, and a data management platform. This includes the following: 
1. Customer engagement in real-time
2. Email and marketing automation
3. Social media engagement, listening and advertising
4. Mobile (SMS) messaging and push notifications
5. Customer marketing analytics
Salesforce Marketing Cloud Email Studio has a range of functions, from standard email services to sophisticated cross-channel capabilities. Salesforce aims to deliver enterprise email marketing functionality to every marketer, making it easy for businesses to scale up their capabilities, whether that means adding extra customer channels to the strategy or sending out millions of emails in one go.
Salesforce Marketing Cloud Email Studio allows marketers to streamline content production using Salesforce’s content management system, Content Builder. Using the system’s tagging and sharing function, it’s possible to create targeted one-to-one emails at scale. Simple drag and drop tools make it easy to create eye catching content to help drive customer engagement, without any coding knowledge needed.

The Marketing Cloud platform SDKs provide a cross-functional framework around the SOAP and REST APIs which allows developers to integrate APIs using native language code libraries by using SOAP and REST APIs to provide agnostic protocol interfaces and automated token management.
In this article, we will elaborate the steps to set up the Python framework for importing your data to your Salesforce Marketing Cloud platform using their REST API endpoints.
First of all, you must have an account on Salesforce Marketing Cloud platform and you will need to set up access credentials for your API calls by following the below steps —
  1. login at Salesforce Marketing Cloud platform as given below -

Creating the credentials on Salesforce Marketing Cloud

2. After successful login, go to setup (under your account in top right corner of the home screen) as given below —

3. After click on the Setup, go to Platform Tools and click on Installed Packages in side Apps as given below —

4. Now, you have to click on the New button as given below -

5. Now, just provide the requested information and click on save button as given below -

6. After creating the package, click on add component and choose API integration as given below —

7. In this section, you have to choose Integration Type as server and fill your account subdomain to enter the URI https://SUBDOMAIN.auth.marketingcloudapis.com/, after click on the save button you will get the following screen -

Now, you have all the credentials such as Client Id, Client Secret, Base, REST base and SOAP base URI as showing in the above screen.

Creating your Python Code — Python is one of the fastest growing programming languages.
1. Whether it’s data manipulation with Pandas,
2. Creating visualizations with Seaborn, or
3. Deep learning with TensorFlow,
Python seems to have a tool for everything.

Installation — The Fuel SDK for Python provides easy access to Salesforce Marketing Cloud’s Fuel API Family services, including a collection of REST APIs and a SOAP API. The Fuel SDK for python can be easily installed from the Python Package Index using the pip command. Pip is a tool for installing and managing Python packages.

pip install Salesforce-FuelSDK

These APIs provide access to Salesforce Marketing Cloud functionality via common collection types such as array/hash.

# Add a require statement to reference the Fuel SDK's functionality: import FuelSDK 
import ET_Client

To enable OAuth2 authentication, set useOAuth2Authentication: True in the config.python file or pass it in the params argument to the ET_Client constructor.

#define local variables 
clientid= '<Your Client Id>'
clientsecret='<Your Client Secret>'
subdomain = '<Your Domain Name>'
auth_base_url = f'https://{subdomain}.auth.marketingcloudapis.com/' rest_url = f'https://{subdomain}.rest.marketingcloudapis.com/'
soap_url=f'https://{subdomain}.soap.marketingcloudapis.com/'
#Passing config as a parameter to ET_Client constructor:
myClient = FuelSDK.ET_Client(True, False,
{'clientid': clientid,
'clientsecret':clientsecret,
'useOAuth2Authentication': 'True',
'authenticationurl': auth_base_url,
'applicationType': 'server',
'baseapiurl': rest_url,
'soapendpoint': soap_url})
# Next, create an instance of the ET_Client class:
myClient = FuelSDK.ET_Client()

# Create an instance of the object type we want to work with:
list = FuelSDK.ET_List()

# Associate the ET_Client- object using the auth_stub property:
list.auth_stub = myClient

# Utilize one of the ET_List methods:
response = list.get()

# Print out the results for viewing
print 'Post Status: ' + str(response.status)
print 'Code: ' + str(response.code)
print 'Message: ' + str(response.message)
print 'Result Count: ' + str(len(response.results))
print 'Results: ' + str(response.results)

Read Data into Pandas Dataframe — Pandas is a Python package that provides fast, flexible, and expressive data structures designed to make working with structured (tabular, multidimensional, potentially heterogeneous) and time series data both easy and intuitive. It aims to be the fundamental high-level building block for doing practical, real world data analysis in Python.

#import pandas library package
import pandas as pd
#define dataframe to read response into dataframe
df=pd.DataFrame(response.results)
#load data into csv data file
df.to_csv('salesforce_marketing_cloud_sample.csv', index=False)

The ET_Client class takes care of many of the required steps when accessing Salesforce Marketing Cloud’s API, including retrieving appropriate access tokens, handling token state for managing refresh, and determining the appropriate endpoints for API requests.

To get more info on FuelSDK-Python, please click here

To learn more, please follow us -
To Learn more, please visit our YouTube channel at —
To Learn more, please visit our Instagram account at -
To Learn more, please visit our twitter account at -

Thursday, September 16, 2021

Python — A Tool for Everything

 Data is a tool, an asset for making a better decisions which can be act as a supreme driver of business value. Now a days, Python is one of the fastest growing programming languages. With the help of this programming language, we can easily do the followings —

  1. Data manipulation with Pandas,
  2. Creating fabulous visualizations with Seaborn, or
  3. Scaling Analytics, Deep Learning and AI Data model with TensorFlow,
Python — A Tool for Everything
Python — A Tool for Everything

So, we can trust on the Python language which seems to have a tool for everything.

In the current era, the volumes of data generated continue to grow at a rapid pace across structured, semi structured, and unstructured data types that businesses are now able to store and need to analyze. 
Few years back, Cloud Technology was considered an optional technology environment but now a days, it is the foundation for modernizing data management and most of the organizations use cloud services or infrastructure widely in their data architecture.
Pandas Library

Pandas is a Python package that provides fast, flexible, and expressive data structures designed to make working with structured like tabular, multidimensional, potentially heterogeneous and time series data both easy and intuitive. It aims to be the fundamental high-level building block for doing practical, real world data analysis in Python.

OS comes under Python’s standard utility modules. This module provides a portable way of using operating system-dependent functionality. os.listdir(‘your_path’) will list all content of a directory

NumPy is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays.

SQLite3 can be integrated with Python using sqlite3 module, which provides an SQL interface compliant with the DB-API 2.0 specification described by PEP 249. You do not need to install this module separately because it is shipped by default along with Python version 2.5.x onwards.

Seaborn is a Python data visualization library based on matplotlib. It will be used to visualize random distributions and provides a high-level interface for drawing attractive and informative statistical graphics.

Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python, and its numerical mathematics extension NumPy. It provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like Tkinter, wxPython, Qt, or GTK.

TensorFlow is a free and open-source software library for machine learning and artificial intelligence. It is an end-to-end open source machine learning platform for everyone and can be used across a range of tasks but has a particular focus on training and inference of deep neural networks. TensorFlow is a symbolic math library based on dataflow and differentiable programming.

Note: 
1.
Seaborn supports Python 3.7+ and no longer supports Python 2.
2. TensorFlow now supports Python 3.5.x through Python 3.8.x, but you still have to use a 64-bit version.

Thursday, August 26, 2021

Python - Common Functions for Exploratory Data Analysis

In this tutorial, we will learn "Common Functions for Exploratory Data Analysis" in our Data Science processes by using Python.

Python is one of the fastest growing programming languages.
1. Whether it’s data manipulation with Pandas,
2. Creating visualizations with Seaborn, or
3. Deep learning with TensorFlow,
Python seems to have a tool for everything.

Pandas is a Python package that provides fast, flexible, and expressive data structures designed to make working with structured (tabular, multidimensional, potentially heterogeneous) and time series data both easy and intuitive. It aims to be the fundamental high-level building block for doing practical, real world data analysis in Python.

NumPy is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays.

In the Data Science, in the most cases is not to explore the data but it is something about to analyze the data in some way, often through a model.

Pandas DataFrame is a 2-dimensional labeled data structure with columns of potentially different types. It is similar to an excel spreadsheet or SQL table, or a dict of Series objects. It is generally the most commonly used pandas object. Like Series, DataFrame accepts many different kinds of input:

• Dict of 1D ndarrays, lists, dicts, or Series

• 2-D numpy.ndarray

• Structured or record ndarray

• A Series

• Another DataFrame

Along with the data, we can optionally pass index (row labels) and columns (column labels) arguments. After passing an index and / or columns, we are guaranteeing the index and / or columns of the resulting DataFrame. Thus, a dict of Series plus a specific index will discard all data not matching up to the passed index

1. Pandas.Dataframe.describe() is very informative function which is used to generate descriptive statistics of the data in a Pandas DataFrame or Series. It summarizes central tendency and dispersion of the dataset. describe() helps in getting a quick overview of the dataset.

2. Head and tail functions - If you want to view a small sample of a Series or DataFrame object, use the head() and tail() methods. The default number of elements to display is five, but you may pass a custom number.

import pandas as pd

import numpy as np

 

#Create a series with random numbers

s = pd.Series(np.random.randn(400))

 

#The first two rows of the data series:

print(s.head(2))

 

#The last two rows of the data series:

print(s.tail(2))

 

#Create a Dictionary of series

d = {'Name':pd.Series(['Tom','James','Ricky','Vin','Steve','Smith','Jack']),

'Age':pd.Series([25,26,25,23,30,29,23]),

'Rating':pd.Series([4.23,3.24,3.98,2.56,3.20,4.6,3.8])}

 

#Create a DataFrame

df = pd.DataFrame(d)

 

#The first two rows of the data frame

print(df.head(2))

 

#The last two rows of the data frame

print(print df.tail(2))


As we know Exploratory Data Analysis (EDA) is one of the most essential part of your data science process.

To learn more, please follow us -

http://www.sql-datatools.com
To Learn more, please visit our YouTube channel at -
http://www.youtube.com/c/Sql-datatools
To Learn more, please visit our Instagram account at -
https://www.instagram.com/asp.mukesh/
To Learn more, please visit our twitter account at -
https://twitter.com/macxima

Popular Posts