{"id":37067737,"url":"https://github.com/anomalous254/daraja_client","last_synced_at":"2026-01-14T07:57:48.556Z","repository":{"id":263447751,"uuid":"890437005","full_name":"anomalous254/daraja_client","owner":"anomalous254","description":"This python module provides a simple way to integrate the Safaricom MPESA Daraja 2.0 API into your Python projects. It is designed to handle common operations like generating access tokens, formatting phone numbers, and sending STK Push requests.","archived":false,"fork":false,"pushed_at":"2024-12-02T12:02:41.000Z","size":60,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-29T18:23:57.151Z","etag":null,"topics":["api-client","api-rest","daraja","daraja-api","daraja-mpesa","oop","python3"],"latest_commit_sha":null,"homepage":"","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/anomalous254.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-11-18T15:08:15.000Z","updated_at":"2024-12-16T15:31:41.000Z","dependencies_parsed_at":"2024-11-18T16:54:43.905Z","dependency_job_id":"eba4ae06-45ca-49fb-9280-4eab0fbc3c46","html_url":"https://github.com/anomalous254/daraja_client","commit_stats":null,"previous_names":["anomalous254/daraja_client"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/anomalous254/daraja_client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anomalous254%2Fdaraja_client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anomalous254%2Fdaraja_client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anomalous254%2Fdaraja_client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anomalous254%2Fdaraja_client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anomalous254","download_url":"https://codeload.github.com/anomalous254/daraja_client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anomalous254%2Fdaraja_client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28413527,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T05:26:33.345Z","status":"ssl_error","status_checked_at":"2026-01-14T05:21:57.251Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["api-client","api-rest","daraja","daraja-api","daraja-mpesa","oop","python3"],"created_at":"2026-01-14T07:57:47.693Z","updated_at":"2026-01-14T07:57:48.550Z","avatar_url":"https://github.com/anomalous254.png","language":"Python","readme":"\n# MPESA Daraja 2.0 API Python Client Module\n\nThis python module provides a simple way to integrate the Safaricom MPESA Daraja 2.0 API into your Python projects. It is designed to handle common operations like generating access tokens, formatting phone numbers, and sending STK Push requests.\n\n## Features\n\n- Generate access tokens securely.\n- Format and validate phone numbers.\n- Send STK Push requests for payments.\n- Easily configurable with environment variables.\n\n## 🛠️ Installation\n\n### From PyPI\nInstall the library directly from PyPI:\n```bash\npip install daraja-client\n```\n\n### From Source\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/anomalous254/daraja_client.git\n   ```\n\n2. Navigate to the project directory:\n   ```bash\n   cd daraja_client\n   ```\n\n3. Install dependencies:\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n## Configuration\n\nAdd the following variables to your `.env` file in the root directory of your project:\n\n```env\nDARAJA_API_CONSUMER_KEY='your_consumer_key'\nDARAJA_API_CONSUMER_SECRET='your_consumer_secret'\nDARAJA_API_PASS_KEY='your_pass_key'\nDARAJA_API_SHORT_CODE='your_shortcode'\n```\n\n## Usage\n\n### Import the Library\n\n```python\nfrom daraja_client.core import DarajaClient\nfrom decouple import config\n\n# Configuration\nauth_url = \"https://sandbox.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials\"\nstk_push_url = 'https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest'\ncall_back_url = 'https://your-callback-url.com' # \nphone_number = '+254769507699' # person to receive the prompt\namount = '1'\n\n# Initialize the client\ncl = DarajaClient(\n    auth_url=auth_url,\n    consumer_key=config('DARAJA_API_CONSUMER_KEY'),\n    consumer_secret=config('DARAJA_API_CONSUMER_SECRET'),\n    pass_key=config('DARAJA_API_PASS_KEY'),\n    shortcode=config('DARAJA_API_SHORT_CODE'),\n    phone_number=phone_number,\n    call_back_url=call_back_url,\n    amount=amount\n)\n\n# Send STK Push\nresponse = cl.send_stk_push(stk_push_url=stk_push_url)\nprint(response)\n```\n\n## Response Examples\n\n### Success\n\n```json\n{\n    \"message\": \"success\",\n    \"stkpushID\": \"ws_CO_blahblahblah\",\n    \"info\": \"You can use and store this stkpushID in your db model to be used for payment confirm during callback from Safaricom\"\n}\n```\n\n### Failure\n\n```json\n{\n    \"message\": \"failed\",\n    \"error\": \"Wrong credentials\"\n}\n```\n\n## Acknowledgment\n\nThis library was developed by [Peter Nyando](https://nyando-tech.vercel.app/), a passionate software engineer dedicated to creating scalable and efficient solutions. Check out more of my work on my [portfolio](https://nyando-tech.vercel.app/).\n\n\nEnsure your `.env` file is properly configured.\n\n\n## Contributing\n\n1. Fork the repository.\n2. Create a new branch.\n3. Make your changes and commit them.\n4. Push to your fork and submit a pull request.\n\n## License\n\nThis project is licensed under the MIT License. See the `LICENSE` file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanomalous254%2Fdaraja_client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanomalous254%2Fdaraja_client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanomalous254%2Fdaraja_client/lists"}