Title: Make SendGrid Endpoint URL a Global Constant for Easier Custom Implementation · Issue #1079 · sendgrid/sendgrid-python · GitHub
Open Graph Title: Make SendGrid Endpoint URL a Global Constant for Easier Custom Implementation · Issue #1079 · sendgrid/sendgrid-python
X Title: Make SendGrid Endpoint URL a Global Constant for Easier Custom Implementation · Issue #1079 · sendgrid/sendgrid-python
Description: Introduction Hello, I would like to suggest an enhancement to the SendGrid Python client. Currently, the endpoint URL for sending emails is embedded within the client implementation. To improve flexibility and make it easier for develope...
Open Graph Description: Introduction Hello, I would like to suggest an enhancement to the SendGrid Python client. Currently, the endpoint URL for sending emails is embedded within the client implementation. To improve fle...
X Description: Introduction Hello, I would like to suggest an enhancement to the SendGrid Python client. Currently, the endpoint URL for sending emails is embedded within the client implementation. To improve fle...
Opengraph URL: https://github.com/sendgrid/sendgrid-python/issues/1079
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Make SendGrid Endpoint URL a Global Constant for Easier Custom Implementation","articleBody":"### Introduction\r\n\r\nHello,\r\n\r\nI would like to suggest an enhancement to the SendGrid Python client. Currently, the endpoint URL for sending emails is embedded within the client implementation. To improve flexibility and make it easier for developers to send emails without using the SendGrid client, I propose the following changes:\r\n\r\n1. Define the endpoint URL as a global constant:\r\n\r\nCreate a separate configuration file (e.g., config.py) that contains the endpoint URL, such as \"https://api.sendgrid.com/v3/mail/send\". This way, the URL can be easily referenced and modified if needed.\r\n\r\n2. Construct the URL using base and version constants:\r\n\r\nInstead of hardcoding the full endpoint URL, define the base URL and version separately, and construct the full URL dynamically. This allows for easier updates and maintenance.\r\n\r\n \r\n### Proposed Changes:\r\n \r\n- Create a config.py file with the following content:\r\n\r\n```python\r\n# config.py\r\nBASE_URL = \"https://api.sendgrid.com\"\r\nAPI_VERSION = \"v3\"\r\nSEND_EMAIL_ENDPOINT = f\"{BASE_URL}/{API_VERSION}/mail/send\"\r\n```\r\n\r\n- Update the existing code to use the global constant:\r\n\r\n```python\r\nfrom .config import SEND_EMAIL_ENDPOINT\r\n\r\nclass BaseInterface(object):\r\n def __init__(self, auth, impersonate_subuser):\r\n self.auth = auth\r\n self.impersonate_subuser = impersonate_subuser\r\n self.version = __version__\r\n self.useragent = 'sendgrid/{};python'.format(self.version)\r\n self.host = SEND_EMAIL_ENDPOINT\r\n \r\n self.client = python_http_client.Client(\r\n host=self.host,\r\n request_headers=self._default_headers,\r\n version=3\r\n )\r\n\r\n```\r\n\r\n- Example for sending emails using requests:\r\n\r\n```python\r\nimport requests\r\nfrom .config import SEND_EMAIL_ENDPOINT\r\n\r\ndef send_email(api_key, from_email, to_email, subject, content):\r\n headers = {\r\n \"Authorization\": f\"Bearer {api_key}\",\r\n \"Content-Type\": \"application/json\"\r\n }\r\n data = {\r\n \"personalizations\": [\r\n {\r\n \"to\": [{\"email\": to_email}],\r\n \"subject\": subject\r\n }\r\n ],\r\n \"from\": {\"email\": from_email},\r\n \"content\": [{\"type\": \"text/plain\", \"value\": content}]\r\n }\r\n response = requests.post(SEND_EMAIL_ENDPOINT, headers=headers, json=data)\r\n return response\r\n\r\n# Example usage\r\napi_key = \"your_sendgrid_api_key\"\r\nresponse = send_email(api_key, \"from@example.com\", \"to@example.com\", \"Subject\", \"Email content\")\r\nprint(response.status_code, response.json())\r\n```\r\n\r\nThese changes will provide more flexibility for developers and make the codebase easier to maintain.\r\n\r\nThank you for considering this enhancement.\r\n\r\nBest regards,","author":{"url":"https://github.com/fredericogago","@type":"Person","name":"fredericogago"},"datePublished":"2024-05-21T15:00:04Z","url":"https://github.com/sendgrid/sendgrid-python/issues/1079"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:845788f2-36da-190d-11ef-8afc9ad338c2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D04E:17E4EA:71F791:97BC2F:6B062D10 |
| html-safe-nonce | 8674bf3ddcead50ae2852c7e364ac1965b92d925e09e2a0a9b29ebdf5718d0ab |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMDRFOjE3RTRFQTo3MUY3OTE6OTdCQzJGOjZCMDYyRDEwIiwidmlzaXRvcl9pZCI6IjYzNTc1MTE4NzI5NTg1NzM4NDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 807a920a1421eaf023d13d302e7178424e0a86ded98e2d6f86cc924ba61215f2 |
| hovercard-subject-tag | issue:2308513185 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/sendgrid/sendgrid-python/1079/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5b263f00951e0cf9c2e202c1151f0cefb72545eee037455a0edc51d017a45103/sendgrid/sendgrid-python/issues/1079 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5b263f00951e0cf9c2e202c1151f0cefb72545eee037455a0edc51d017a45103/sendgrid/sendgrid-python/issues/1079 |
| og:image:alt | Introduction Hello, I would like to suggest an enhancement to the SendGrid Python client. Currently, the endpoint URL for sending emails is embedded within the client implementation. To improve fle... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fredericogago |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7f961de5dd5c5d4aca24d33f8b3ffb3fb8b2ef53d0a4f32f01f0a790e512f6d3 |
| turbo-cache-control | no-preview |
| go-import | github.com/sendgrid/sendgrid-python git https://github.com/sendgrid/sendgrid-python.git |
| octolytics-dimension-user_id | 181234 |
| octolytics-dimension-user_login | sendgrid |
| octolytics-dimension-repository_id | 3546794 |
| octolytics-dimension-repository_nwo | sendgrid/sendgrid-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3546794 |
| octolytics-dimension-repository_network_root_nwo | sendgrid/sendgrid-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 494ea0bb1e0feef734a83e2628697647755e8864 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width