{"componentChunkName":"component---src-templates-markdown-template-jsx","path":"/https/docs.mparticle.com/developers/server-sdks/python/","result":{"data":{"pageMetadata":{"title":"Python SDK","path":"/https/docs.mparticle.com/developers/server-sdks/python/","sourceCode":null,"metadataParent":{"title":"Server SDKs","path":"/https/docs.mparticle.com/developers/server-sdks/","sourceCode":null,"hasVersionPicker":null,"metadataChildren":[{"title":"Node SDK","path":"/https/docs.mparticle.com/developers/server-sdks/node/","order":3,"label":null},{"title":"Go SDK","path":"/https/docs.mparticle.com/developers/server-sdks/go/","order":4,"label":null},{"title":"Python SDK","path":"/https/docs.mparticle.com/developers/server-sdks/python/","order":4,"label":null},{"title":"Ruby SDK","path":"/https/docs.mparticle.com/developers/server-sdks/ruby/","order":5,"label":null},{"title":"Java SDK","path":"/https/docs.mparticle.com/developers/server-sdks/java/","order":6,"label":null}],"metadataParent":{"title":"Developers","path":"/https/docs.mparticle.com/developers/","metadataChildren":[{"title":"API Credential Management","path":"/https/docs.mparticle.com/developers/credential-management/","order":null,"label":null},{"title":"API References","path":"/https/docs.mparticle.com/developers/apis/","order":null,"label":null},{"title":"Client SDKs","path":"/https/docs.mparticle.com/developers/client-sdks/","order":null,"label":null},{"title":"Guides","path":"/https/docs.mparticle.com/developers/guides/","order":null,"label":null},{"title":"Media SDKs","path":"/https/docs.mparticle.com/developers/media-sdks/","order":null,"label":null},{"title":"Quickstart","path":"/https/docs.mparticle.com/developers/quickstart/","order":null,"label":null},{"title":"Server SDKs","path":"/https/docs.mparticle.com/developers/server-sdks/","order":null,"label":null},{"title":"The Developer's Guided Journey to mParticle","path":"/https/docs.mparticle.com/developers/developersjourney/","order":null,"label":null},{"title":"Tools","path":"/https/docs.mparticle.com/developers/tools/","order":null,"label":null}],"metadataParent":null}}},"markdownRemark":{"html":"<p>The Python SDK is a helper library for the mParticle Events HTTP API that exposes the mParticle schema as simple models and provides an HTTP client interface. This SDK is stateless and only sends the data that you populate, whereas our mobile SDKs automatically collect app and device information, session events, install events, and maintain persistence. </p>\n<p>Though the SDK may work on earlier versions of Python, we officially support Python version 3.5 or higher.</p>\n<p>Read this page for a general overview and examples, visit the <a href=\"https://github.com/mParticle/mparticle-python-sdk\">Python SDK repo</a>), and if needed, <a href=\"https://support.mparticle.com\">contact our customer support team</a> to make sure you’re feeding the platform with the right data to power your integrations.</p>\n<h2 id=\"model-overview\" style=\"position:relative;\"><a href=\"#model-overview\" aria-label=\"model overview permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a>Model Overview</h2>\n<h3 id=\"batch\" style=\"position:relative;\"><a href=\"#batch\" aria-label=\"batch permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a><a href=\"https://github.com/mParticle/mparticle-python-sdk/blob/master/docs/Batch.md\">Batch</a></h3>\n<p>All data sent via the SDK must be encapsulated in a <a href=\"https://github.com/mParticle/mparticle-python-sdk/blob/master/mparticle/models/batch.py\">Batch</a> object. Each Batch is associated with a <strong>single user</strong>. Batch objects must be associated with an environment (<code class=\"language-text\">production</code> or <code class=\"language-text\">development</code>) to properly silo your testing and production data.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-python line-numbers\"><code class=\"language-python\"><span class=\"token keyword\">import</span> mparticle\nbatch <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>Batch<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nbatch<span class=\"token punctuation\">.</span>environment <span class=\"token operator\">=</span> <span class=\"token string\">'development'</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span></span></pre></div>\n<h3 id=\"user-identities\" style=\"position:relative;\"><a href=\"#user-identities\" aria-label=\"user identities permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a>User Identities</h3>\n<p>Most use-cases require that data be associated with a user identity, for example:</p>\n<ul>\n<li>If you’re also sending data to mParticle via our mobile SDKs, set a customer ID both via the mobile SDKs and this SDK so that mParticle can correctly associate data with each user.</li>\n<li>Several marketing automation and audience integrations are powered by email. </li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-python line-numbers\"><code class=\"language-python\">identities <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>UserIdentities<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nidentities<span class=\"token punctuation\">.</span>customerid <span class=\"token operator\">=</span> <span class=\"token string\">'123456'</span>\nidentities<span class=\"token punctuation\">.</span>email <span class=\"token operator\">=</span> <span class=\"token string\">'user@example.com'</span>\nbatch<span class=\"token punctuation\">.</span>user_identities <span class=\"token operator\">=</span> identities</code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span></span></pre></div>\n<h3 id=\"device-information\" style=\"position:relative;\"><a href=\"#device-information\" aria-label=\"device information permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a>Device Information</h3>\n<p>The <code class=\"language-text\">DeviceInformation</code> object describes a mobile device that should be associated with this batch. Crucially, it exposes properties for device identities (Apple IDFA and Google Advertising ID) which are required for nearly all mParticle Audience integrations.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-python line-numbers\"><code class=\"language-python\">device_info <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>DeviceInformation<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n<span class=\"token comment\"># set any IDs that you have for this user</span>\ndevice_info<span class=\"token punctuation\">.</span>ios_advertising_id <span class=\"token operator\">=</span> <span class=\"token string\">'07d2ebaa-e956-407e-a1e6-f05f871bf4e2'</span>\ndevice_info<span class=\"token punctuation\">.</span>android_advertising_id <span class=\"token operator\">=</span> <span class=\"token string\">'a26f9736-c262-47ea-988b-0b0504cee874'</span>\nbatch<span class=\"token punctuation\">.</span>device_info <span class=\"token operator\">=</span> device_info</code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span></span></pre></div>\n<h3 id=\"user-attributes\" style=\"position:relative;\"><a href=\"#user-attributes\" aria-label=\"user attributes permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a>User Attributes</h3>\n<p>The mParticle audience platform can be powered by only sending a combination of user attributes, used to describe segments of users, and device identities/user identities used to then target those users.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-python line-numbers\"><code class=\"language-python\"><span class=\"token comment\"># arbitrary example allowing you to create a segment of users trial users</span>\nbatch<span class=\"token punctuation\">.</span>user_attributes <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'Account type'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'trial'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'TrialEndDate'</span><span class=\"token punctuation\">:</span><span class=\"token string\">'2016-12-01'</span><span class=\"token punctuation\">}</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span></span></pre></div>\n<h3 id=\"events\" style=\"position:relative;\"><a href=\"#events\" aria-label=\"events permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a>Events</h3>\n<p>Events are central to many of mParticle’s integrations; analytics integrations typically require events, and you can create mParticle Audiences based on the recency and frequency of different events. All events should be associated with a timestamp reflecting when they actually occurred, otherwise they will be assigned a timestamp when mParticle receives them.</p>\n<h4 id=\"appevent\" style=\"position:relative;\"><a href=\"#appevent\" aria-label=\"appevent permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a>AppEvent</h4>\n<p>App Events represent specific actions that a user has taken in your app. At minimum they require a name and a type, but can also be associate with a free-form dictionary of key/value pairs.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-python line-numbers\"><code class=\"language-python\">app_event <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>AppEvent<span class=\"token punctuation\">(</span><span class=\"token string\">'Example'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'navigation'</span><span class=\"token punctuation\">,</span> custom_attributes<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token string\">'foo'</span><span class=\"token punctuation\">:</span><span class=\"token string\">'bar'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\napp_event<span class=\"token punctuation\">.</span>timestamp_unixtime_ms <span class=\"token operator\">=</span> example_timestamp\nbatch<span class=\"token punctuation\">.</span>events <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>app_event<span class=\"token punctuation\">]</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span></span></pre></div>\n<!--\n##### LTV Increase\n\nMany integrations support the notion of user-lifetime value or eCommerce transactions, and the LTV Increase event is a special-case of AppEvent that includes a monetary value. LTV Increase events are easy to use though much less descriptive than ProductAction events.\n\n```python\napp_event = mparticle.AppEvent('User Value Update', 'transaction')\napp_event.timestamp_unixtime_ms = example_timestamp\napp_event.custom_attributes = { methodname: LogLTVIncrease $amount: 19.99 }\nbatch.events = [app_event]\n```\n-->\n<h4 id=\"commerceevent\" style=\"position:relative;\"><a href=\"#commerceevent\" aria-label=\"commerceevent permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a>CommerceEvent</h4>\n<p>The CommerceEvent is central to mParticle’s eCommerce measurement. CommerceEvents can contain many data points but it’s important to understand that there are 3 core variations:</p>\n<ul>\n<li>Product-based: Used to measure measured datapoints associated with one or more products</li>\n<li>Promotion-base: Used to measure datapoints associated with internal promotions or campaigns</li>\n<li>Impression-based: Used to measure interactions with impressions of products and product-listings</li>\n</ul>\n<p>Custom attributes can be added to both products and commerce events using the <code class=\"language-text\">custom_attributes</code> property, which accepts a dictionary of key/value pairs of strings.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-python line-numbers\"><code class=\"language-python\">product <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>Product<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nproduct<span class=\"token punctuation\">.</span>name <span class=\"token operator\">=</span> <span class=\"token string\">'Example Product'</span>\nproduct<span class=\"token punctuation\">.</span><span class=\"token builtin\">id</span> <span class=\"token operator\">=</span> <span class=\"token string\">'sample-sku'</span>\nproduct<span class=\"token punctuation\">.</span>price <span class=\"token operator\">=</span> <span class=\"token number\">19.99</span>\nproduct<span class=\"token punctuation\">.</span>custom_attributes <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'color'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'red'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'size'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'small'</span><span class=\"token punctuation\">}</span> <span class=\"token comment\"># optional dictionary containing custom attributes for the product</span>\n\nproduct_action <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>ProductAction<span class=\"token punctuation\">(</span><span class=\"token string\">'purchase'</span><span class=\"token punctuation\">)</span>\nproduct_action<span class=\"token punctuation\">.</span>products <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>product<span class=\"token punctuation\">]</span>\nproduct_action<span class=\"token punctuation\">.</span>tax_amount <span class=\"token operator\">=</span> <span class=\"token number\">1.50</span>\nproduct_action<span class=\"token punctuation\">.</span>total_amount <span class=\"token operator\">=</span> <span class=\"token number\">21.49</span>\n\ncommerce_event <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>CommerceEvent<span class=\"token punctuation\">(</span>product_action<span class=\"token punctuation\">)</span>\ncommerce_event<span class=\"token punctuation\">.</span>timestamp_unixtime_ms <span class=\"token operator\">=</span> example_timestamp\ncommerce_event<span class=\"token punctuation\">.</span>custom_attributes <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'sale'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">'true'</span><span class=\"token punctuation\">}</span> <span class=\"token comment\"># optional dictionary containing custom attributes for the commerce event</span>\n\nbatch<span class=\"token punctuation\">.</span>events <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>commerce_event<span class=\"token punctuation\">]</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></pre></div>\n<h4 id=\"session-events\" style=\"position:relative;\"><a href=\"#session-events\" aria-label=\"session events permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a>Session Events</h4>\n<p>The SessionStartEvent and SessionEndEvent should be used to describe the details of user session such as its length, which is a common metric used in many mParticle integrations. Additonally, length, recency, and frequency of sessions are powerful data-points by which an mParticle audience can be defined.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-python line-numbers\"><code class=\"language-python\">session_start <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>SessionStartEvent<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nsession_start<span class=\"token punctuation\">.</span>session_id <span class=\"token operator\">=</span> <span class=\"token number\">12345678</span>\nsession_start<span class=\"token punctuation\">.</span>timestamp_unixtime_ms <span class=\"token operator\">=</span> example_timestamp\n\nsession_end <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>SessionEndEvent<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nsession_end<span class=\"token punctuation\">.</span>session_id <span class=\"token operator\">=</span> session_start<span class=\"token punctuation\">.</span>session_id <span class=\"token comment\"># its mandatory that these match</span>\nsession_end<span class=\"token punctuation\">.</span>session_duration_ms <span class=\"token operator\">=</span> example_duration\nsession_end<span class=\"token punctuation\">.</span>timestamp_unixtime_ms <span class=\"token operator\">=</span> example_timestamp <span class=\"token operator\">+</span> example_duration\n\nbatch<span class=\"token punctuation\">.</span>events <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>session_start<span class=\"token punctuation\">,</span> session_end<span class=\"token punctuation\">]</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></pre></div>\n<h4 id=\"application-state-events\" style=\"position:relative;\"><a href=\"#application-state-events\" aria-label=\"application state events permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a>Application State Events</h4>\n<p>Use these events to represent the nuances of inter- and intra-session user-behavior with your app. Install events are crucial to power many attribution integrations and to judge the success of marketing campaigns.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-python line-numbers\"><code class=\"language-python\">install <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>ApplicationStateTransitionEvent<span class=\"token punctuation\">.</span>create_install_event<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\ninstall<span class=\"token punctuation\">.</span>timestamp_unixtime_ms <span class=\"token operator\">=</span> example_timestamp\n\nupgrade <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>ApplicationStateTransitionEvent<span class=\"token punctuation\">.</span>create_upgrade_event<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nupgrade<span class=\"token punctuation\">.</span>timestamp_unixtime_ms <span class=\"token operator\">=</span> example_timestamp\n\nforeground <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>ApplicationStateTransitionEvent<span class=\"token punctuation\">.</span>create_foreground_event<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nforeground<span class=\"token punctuation\">.</span>timestamp_unixtime_ms <span class=\"token operator\">=</span> example_timestamp\n\nbackground <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>ApplicationStateTransitionEvent<span class=\"token punctuation\">.</span>create_background_event<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nbackground<span class=\"token punctuation\">.</span>timestamp_unixtime_ms <span class=\"token operator\">=</span> example_timestamp</code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></pre></div>\n<h3 id=\"consent-state\" style=\"position:relative;\"><a href=\"#consent-state\" aria-label=\"consent state permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a>Consent State</h3>\n<p>To conform to the ever growing global regulations on data privacy, mParticle provides <a href=\"/guides/data-privacy-controls/\">Data Privacy Controls</a>.</p>\n<p>Data privacy is configured in the dashboard and is attached via a batch’s <code class=\"language-text\">consent_state</code>.</p>\n<h4 id=\"ccpa\" style=\"position:relative;\"><a href=\"#ccpa\" aria-label=\"ccpa permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a>CCPA</h4>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-python line-numbers\"><code class=\"language-python\">ccpa_consent_state <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>CCPAConsentState<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nccpa_consent_state<span class=\"token punctuation\">.</span>document <span class=\"token operator\">=</span> <span class=\"token string\">'document_agreement.v3'</span>\nccpa_consent_state<span class=\"token punctuation\">.</span>consented <span class=\"token operator\">=</span> <span class=\"token boolean\">True</span>\nccpa_consent_state<span class=\"token punctuation\">.</span>timestamp_unixtime_ms <span class=\"token operator\">=</span> time<span class=\"token punctuation\">.</span>time_ns<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">//</span> <span class=\"token number\">1000000</span>\nccpa_consent_state<span class=\"token punctuation\">.</span>location <span class=\"token operator\">=</span> <span class=\"token string\">'mparticle.test/signup'</span>\nccpa_consent_state<span class=\"token punctuation\">.</span>hardware_id <span class=\"token operator\">=</span> <span class=\"token string\">'IDFA:a5d96n32-224a-3b11-1088-a202695bc710'</span>\n\nconsent_state <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>ConsentState<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nconsent_state<span class=\"token punctuation\">.</span>ccpa <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'data_sale_opt_out'</span><span class=\"token punctuation\">:</span> ccpa_consent_state<span class=\"token punctuation\">}</span>\n\nbatch<span class=\"token punctuation\">.</span>consent_state <span class=\"token operator\">=</span> consent_state</code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></pre></div>\n<h4 id=\"gdpr\" style=\"position:relative;\"><a href=\"#gdpr\" aria-label=\"gdpr permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a>GDPR</h4>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-python line-numbers\"><code class=\"language-python\">gdpr_consent_state <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>GDPRConsentState<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\ngdpr_consent_state<span class=\"token punctuation\">.</span>document <span class=\"token operator\">=</span> <span class=\"token string\">'document_agreement.v2'</span>\ngdpr_consent_state<span class=\"token punctuation\">.</span>consented <span class=\"token operator\">=</span> <span class=\"token boolean\">True</span>\ngdpr_consent_state<span class=\"token punctuation\">.</span>timestamp_unixtime_ms <span class=\"token operator\">=</span> time<span class=\"token punctuation\">.</span>time_ns<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">//</span> <span class=\"token number\">1000000</span>\ngdpr_consent_state<span class=\"token punctuation\">.</span>location <span class=\"token operator\">=</span> <span class=\"token string\">'dtmgbank.com/signup'</span>\ngdpr_consent_state<span class=\"token punctuation\">.</span>hardware_id <span class=\"token operator\">=</span> <span class=\"token string\">'IDFA:a5d934n0-232f-4afc-2e9a-3832d95zc702'</span>\n\nconsent_state <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>ConsentState<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nconsent_state<span class=\"token punctuation\">.</span>gdpr <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span><span class=\"token string\">'My Purpose'</span><span class=\"token punctuation\">:</span> gdpr_consent_state<span class=\"token punctuation\">}</span>\n\nbatch<span class=\"token punctuation\">.</span>consent_state <span class=\"token operator\">=</span> consent_state</code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></pre></div>\n<p>In this example, <code class=\"language-text\">&#39;My Purpose&#39;</code> should match the <strong>Consent Purpose</strong> defined in your GDPR Setting</p>\n<h2 id=\"http-client-usage\" style=\"position:relative;\"><a href=\"#http-client-usage\" aria-label=\"http client usage permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a>HTTP Client Usage</h2>\n<p>The SDK provides an interface to the mParticle HTTP API by way of the EventsApi class.</p>\n<h3 id=\"configuration\" style=\"position:relative;\"><a href=\"#configuration\" aria-label=\"configuration permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a><a href=\"https://github.com/mParticle/mparticle-python-sdk/blob/master/mparticle/configuration.py\">Configuration</a></h3>\n<p>At minimum, the <code class=\"language-text\">EventsApi</code> must be initialized with an mParticle key and secret. You can find your mParticle key and secret by navigating to the <a href=\"https://app.mparticle.com/setup/inputs/apps\">Apps</a> section of the mParticle platform UI.</p>\n<blockquote>\n<p>You must associate your data with the correct key and secret. If your app is multi-platform, for example, be sure to send your Android data to your Android key/secret, and your iOS data to your iOS key/secret.</p>\n</blockquote>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-python line-numbers\"><code class=\"language-python\">configuration <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>Configuration<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\nconfiguration<span class=\"token punctuation\">.</span>api_key <span class=\"token operator\">=</span> <span class=\"token string\">'REPLACE WITH APP KEY'</span>\nconfiguration<span class=\"token punctuation\">.</span>api_secret <span class=\"token operator\">=</span> <span class=\"token string\">'REPLACE WITH APP SECRET'</span>\nconfiguration<span class=\"token punctuation\">.</span>debug <span class=\"token operator\">=</span> <span class=\"token boolean\">True</span> <span class=\"token comment\">#enable logging of HTTP traffic</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span></span></pre></div>\n<p>If your workspace is in a pod other than US1, make sure to set the host to the <a href=\"https://docs.mparticle.com/developers/apis/http/#endpoint\">appropriate URL</a>.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-python line-numbers\"><code class=\"language-python\"><span class=\"token comment\"># Example for the EU1 pod, replace eu1 with the pod's name</span>\nconfiguration<span class=\"token punctuation\">.</span>host <span class=\"token operator\">=</span> <span class=\"token string\">'https://s2s.eu1.mparticle.com/v2'</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span></span></pre></div>\n<p>Finally, initialize the SDK with the configuration.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-python line-numbers\"><code class=\"language-python\">api_instance <span class=\"token operator\">=</span> mparticle<span class=\"token punctuation\">.</span>EventsApi<span class=\"token punctuation\">(</span>configuration<span class=\"token punctuation\">)</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span></span></pre></div>\n<h3 id=\"uploading-data\" style=\"position:relative;\"><a href=\"#uploading-data\" aria-label=\"uploading data permalink\" class=\"anchor before\"><svg width=\"16px\" height=\"17px\" viewBox=\"0 0 16 17\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n                <g id=\"Symbols\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n                    <g id=\"Icon/Link\" fill=\"#98A0A3\" fill-rule=\"nonzero\">\n                        <g id=\"link\">\n                            <path d=\"M9.5,12.4 C9.6,12.4 9.7,12.4 9.9,12.4 C9.8,12.5 9.8,12.5 9.7,12.6 L7.5,14.8 C5.8,16.5 3,16.5 1.3,14.8 C-0.4,13.1 -0.4,10.3 1.3,8.6 L3.5,6.4 C3.6,6.3 3.6,6.3 3.7,6.2 C5,5 6.9,4.8 8.4,5.5 C8.8,5.7 9.3,6 9.6,6.4 C10,6.7 10.2,7.2 10.5,7.6 C10.2,7.9 9.9,8 9.5,8 C9.4,8 9.2,8 9.1,7.9 C8.9,7.5 8.5,7.2 8.1,6.9 C7,6.2 5.5,6.4 4.5,7.3 L3.8,8 L2.3,9.5 C1.2,10.6 1.2,12.5 2.3,13.6 C3.4,14.7 5.3,14.7 6.4,13.6 L7.9,12.1 C8.4,12.3 8.9,12.4 9.5,12.4 Z M14.7,1.3 C13,-0.4 10.2,-0.4 8.5,1.3 L6.3,3.5 C6.2,3.6 6.2,3.6 6.1,3.7 C6.7,3.7 7.4,3.7 8,3.9 L9.5,2.4 C10.6,1.3 12.5,1.3 13.6,2.4 C14.7,3.5 14.7,5.4 13.6,6.5 L12.1,8 L11.4,8.7 C10.4,9.7 8.9,9.8 7.8,9.1 C7.4,8.9 7.1,8.5 6.8,8.1 C6.7,8.1 6.5,8 6.4,8 C6,8 5.6,8.2 5.4,8.4 C5.6,8.8 5.9,9.3 6.3,9.6 C6.6,10 7.1,10.2 7.5,10.5 C9,11.2 10.9,11 12.3,9.8 C12.4,9.7 12.4,9.7 12.5,9.6 L14.7,7.4 C16.4,5.7 16.4,3 14.7,1.3 Z\" id=\"Shape\"></path>\n                        </g>\n                    </g>\n                </g>\n            </svg></a>Uploading Data</h3>\n<p>The EventsAPI class exposes two interfaces:</p>\n<ul>\n<li><code class=\"language-text\">bulk_upload_events</code> - Accepts up to 100 <code class=\"language-text\">Batch</code> objects for up to 100 users.</li>\n<li><code class=\"language-text\">upload_events</code> - Accepts a single <code class=\"language-text\">Batch</code> object for a single user</li>\n</ul>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-python line-numbers\"><code class=\"language-python\"><span class=\"token keyword\">try</span><span class=\"token punctuation\">:</span> \n    api_instance<span class=\"token punctuation\">.</span>upload_events<span class=\"token punctuation\">(</span>batch<span class=\"token punctuation\">)</span>\n    <span class=\"token comment\"># you can also send multiple batches at a time to decrease the amount of network calls</span>\n    <span class=\"token comment\">#api_instance.bulk_upload_events([batch, batch])</span>\n<span class=\"token keyword\">except</span> mparticle<span class=\"token punctuation\">.</span>rest<span class=\"token punctuation\">.</span>ApiException <span class=\"token keyword\">as</span> e<span class=\"token punctuation\">:</span>\n    <span class=\"token keyword\">print</span><span class=\"token punctuation\">(</span><span class=\"token string-interpolation\"><span class=\"token string\">f'Exception while calling mParticle: %</span><span class=\"token interpolation\"><span class=\"token punctuation\">{</span>e<span class=\"token punctuation\">}</span></span><span class=\"token string\">\\n'</span></span><span class=\"token punctuation\">)</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span><span></span></span></pre></div>","frontmatter":{"title":"Python SDK","order":4,"seoTitle":null,"seoDescription":null},"parent":{"__typename":"File","modifiedTime":"August 7, 2026"}}},"pageContext":{"slug":"/developers/server-sdks/python/"}},"staticQueryHashes":["2950460867"]}