{"id":23084296,"url":"https://github.com/swetrix/python-sdk","last_synced_at":"2025-04-03T14:41:32.524Z","repository":{"id":245013854,"uuid":"817003755","full_name":"Swetrix/python-sdk","owner":"Swetrix","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-14T20:33:08.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-28T13:49:19.213Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Swetrix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-18T20:25:13.000Z","updated_at":"2024-08-14T20:33:12.000Z","dependencies_parsed_at":"2024-06-19T02:36:12.623Z","dependency_job_id":"54af1e21-13c0-45a9-8099-616a24834bfa","html_url":"https://github.com/Swetrix/python-sdk","commit_stats":null,"previous_names":["swetrix/python-sdk"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Swetrix%2Fpython-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Swetrix%2Fpython-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Swetrix%2Fpython-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Swetrix%2Fpython-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Swetrix","download_url":"https://codeload.github.com/Swetrix/python-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247022886,"owners_count":20870885,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-16T15:50:51.186Z","updated_at":"2025-04-03T14:41:32.497Z","avatar_url":"https://github.com/Swetrix.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swetrix Python SDK\n\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nThe Swetrix Python SDK is a client library designed to interact with the Swetrix API. This SDK provides easy-to-use methods for tracking and analyzing various events, user interactions, and metrics within your Python applications.\n\n## Features\n\n- Simple integration with Swetrix API.\n- Track various events and user interactions.\n- Collect and analyze custom metrics.\n- Lightweight and easy to use.\n\n## Installation\n\nYou can install the SDK using pip:\n\n```bash\npip install swetrix-sdk\n```\n\n## Usage\n\nBelow is a basic example of how to use the Swetrix Python SDK to send events to Swetrix.\n\n### Environment Variables\n\n```bash\n# In your .env file or environment\nSWETRIX_PROJECT_ID=your_project_id\nSWETRIX_API_KEY=your_api_key\n```\n\nAlternatively, you can pass these values directly to the `Swetrix` instance.\n\n## Basic Usage\n\n### Initialization\n\nInitialize the Swetrix client with your `PROJECT_ID` and `API_KEY`.\n\n```python\nfrom swetrix_sdk import Swetrix\nfrom enums import CustomEventType, PageViewOption\n\n# Initialize Swetrix instance\nswetrix = Swetrix(\n    project_id='your_project_id',\n    api_key='your_api_key',\n    enable_logging=True  # Enable logging for debugging\n)\n```\n\n### Tracking Custom Events\n\nUse the `track_event` method to track any custom event. Here's an example where we track a \"signup\" event:\n\n```python\nevent_data = {\n    PageViewOption.SOURCE: \"homepage\",\n    PageViewOption.METHOD: \"google\"\n}\n\nswetrix.track_event(\n    ip=\"192.168.0.1\",\n    user_agent=\"Mozilla/5.0\",\n    event_type=CustomEventType.SIGNUP,\n    event_options=event_data\n)\n```\n\n### Tracking Page Views\n\nYou can easily track page views by providing the necessary options like `URL` and `User ID`.\n\n```python\npage_view_data = {\n    PageViewOption.URL: \"/homepage\",\n    PageViewOption.USER_ID: \"user123\"\n}\n\nswetrix.track_page_view(\n    ip=\"192.168.0.1\",\n    user_agent=\"Mozilla/5.0\",\n    page_view_options=page_view_data\n)\n```\n\n## Using Decorators for Automatic Event Tracking\n\nThe SDK provides decorators that automatically track events or page views whenever a function is called. This is useful for tracking specific function executions, like API endpoints.\n\n### Tracking Custom Events with a Decorator\n\nTo automatically track an event when a function is executed, use the `track_event_decorator`:\n\n```python\n@swetrix.track_event_decorator(\n    ip=\"192.168.0.1\",\n    user_agent=\"Mozilla/5.0\",\n    event_type=CustomEventType.LOGIN,\n    event_options={PageViewOption.SOURCE: \"login_page\"}\n)\ndef user_login(username: str, password: str):\n    return \"User logged in\"\n\n# Call the decorated function\nuser_login(\"Yehor\", \"Python\")\n```\n\n### Tracking Page Views with a Decorator\n\nSimilarly, you can use the `track_page_view_decorator` to track page views when a function is executed.\n\n```python\n@swetrix.track_page_view_decorator(\n    ip=\"192.168.0.1\",\n    user_agent=\"Mozilla/5.0\",\n    page_view_options={PageViewOption.URL: \"/profile\", PageViewOption.USER_ID: \"user123\"}\n)\ndef load_profile():\n    return \"Profile loaded\"\n\nload_profile()\n```\n\n## Configuration Options\n\n- `project_id`: The project ID for Swetrix.\n- `api_key`: The API key for Swetrix.\n- `options`: Additional configuration options for custom API URLs.\n- `enable_logging`: Boolean flag to enable or disable logging.\n\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n### Steps to Contribute\n\n1. Fork the repository.\n2. Create a new branch for your feature or bugfix.\n3. Make your changes.\n4. Submit a pull request.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.\n\n## Support\n\nFor any issues or support requests, please open an issue on the [GitHub Issues](https://github.com/Swetrix/python-sdk/issues) page.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswetrix%2Fpython-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswetrix%2Fpython-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswetrix%2Fpython-sdk/lists"}