{"id":1900,"library":"amplitude-analytics","title":"Amplitude Python SDK","description":"The official Amplitude backend Python SDK provides server-side instrumentation for tracking analytics events. Currently at version 1.2.3, it offers functionalities to send events, manage user properties, and track revenue, with regular patch and minor releases to enhance stability and features.","status":"active","version":"1.2.3","language":"en","source_language":"en","source_url":"https://github.com/amplitude/Amplitude-Python","tags":["analytics","event tracking","backend","amplitude","sdk"],"install":[{"cmd":"pip install amplitude-analytics","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"Amplitude","correct":"from amplitude import Amplitude"},{"symbol":"BaseEvent","correct":"from amplitude import BaseEvent"},{"symbol":"Identify","correct":"from amplitude import Identify"}],"quickstart":{"code":"import os\nfrom amplitude import Amplitude, BaseEvent, Identify\nimport time\n\nAMPLITUDE_API_KEY = os.environ.get(\"AMPLITUDE_API_KEY\", \"YOUR_AMPLITUDE_API_KEY\")\n\n# Initialize the SDK\n# For EU data residency, add: server_zone='EU' to Amplitude(API_KEY, ...)\namplitude = Amplitude(AMPLITUDE_API_KEY)\n\n# Example: Configure for EU data residency (uncomment if applicable)\n# amplitude.configuration.server_zone = 'EU'\n\n# Create and track a basic event\nprint(\"Tracking a 'User Logged In' event...\")\nevent = BaseEvent(\n    event_type=\"User Logged In\",\n    user_id=\"user_123\",\n    device_id=\"device_abc\",\n    event_properties={\n        \"login_method\": \"email\",\n        \"timestamp\": int(time.time())\n    }\n)\namplitude.track(event)\n\n# Identify a user and set/update user properties\nprint(\"Setting user properties for 'user_123'...\")\nidentify = Identify()\nidentify.set(\"plan\", \"premium\")\nidentify.set_once(\"initial_referrer\", \"google\") # Set only once\nidentify.add(\"login_count\", 1) # Increment a property\namplitude.identify(\"user_123\", identify)\n\n# Important: Flush events before application exit to ensure delivery\nprint(\"Flushing events...\")\namplitude.flush()\nprint(\"Events sent and flushed. Check your Amplitude project.\")","lang":"python","description":"Initializes the Amplitude SDK with an API key (preferably from environment variables), tracks a custom event, and sets user properties. It emphasizes the importance of calling `flush()` to ensure events are sent before the application terminates, and shows how to configure for EU data residency."},"warnings":[{"fix":"Consult the official Amplitude documentation and release notes for specific migration guides and breaking changes when updating to a new major version.","message":"Major version updates (e.g., v1.x to v2.x) may introduce significant changes to public interfaces, behaviors, or semantics. Always review upgrade guidelines carefully when moving to a new major version.","severity":"breaking","affected_versions":"All major version transitions (e.g., from an hypothetical 0.x to 1.x or 1.x to 2.x)"},{"fix":"Explicitly call `amplitude.flush()` before your application terminates, especially in short-lived scripts or serverless functions. You can also configure `flush_queue_size` and `flush_interval_millis` for batching behavior.","message":"Events are queued in memory and sent in batches. If your application exits immediately after calling `track()`, events might not be sent. You must call `client.flush()` to ensure all buffered events are delivered.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Initialize the SDK with `amplitude = Amplitude(API_KEY, configuration={'server_zone': 'EU'})` or set it via `amplitude.configuration.server_zone = 'EU'` after initialization.","message":"By default, data is sent to Amplitude's US servers. If your project requires EU data residency, you must explicitly configure the `server_zone` to 'EU' during SDK initialization.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Verify that the correct API key is used during `Amplitude` client initialization. If using multiple instances, ensure each is configured with its specific API key and managed distinctly.","message":"Using an incorrect API key or having multiple SDK instances (e.g., different Amplitude projects within the same application) without proper separation can lead to events not being ingested or being sent to the wrong project.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that `user_id` and `device_id` values meet the minimum length requirements (typically 5 characters, configurable via `min_id_length`).","message":"Amplitude has a minimum length requirement for `user_id` and `device_id`. Providing IDs shorter than this minimum can result in 400 errors and events not being tracked.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Distribute your event tracking across time or reduce the frequency of event calls for individual users/devices to stay within the throttling limit.","message":"Amplitude enforces a throttling limit of 30 events per user or device per second. Exceeding this limit can cause events to be throttled and logged with a warning, leading to incomplete data.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}