-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a8b59e7
Showing
106 changed files
with
4,572 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# pdm | ||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | ||
#pdm.lock | ||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it | ||
# in version control. | ||
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control | ||
.pdm.toml | ||
.pdm-python | ||
.pdm-build/ | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
.idea/ | ||
.history/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
What can we say? | ||
|
||
JUST BE NICE TO EACH OTHER! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Coming Soon... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2024 Steve Yonkeu (@yokwejuste) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!-- markdownlint-disable MD033 MD041 --> | ||
<p align="center"> | ||
<h2 align="center">🚀BACKEND SECRETS </h2> | ||
</p> | ||
|
||
<p align="center"> | ||
<img src="https://readme-typing-svg.demolab.com?font=Fira+Code&pause=1000&color=2FF700&random=true&width=435&lines=Analytics%2C+API+Setup;Caching%2C+Database+Configuration;Backend+Developments+and+Docker;Email+Setup%2C+Secret+Management;Infrastructure+As+A+Code%2C+Machine+Learning;Logging%2C+Monitoring%2C+Analytics;RESTFul+APIs%2C+GraphQL%2C+SOAP%2C+gRPC;Unit+Testing+and+CI+CD;Webhooks+and+Web+Sockets+working+with+Database;Web+Scraping%2C+Third+party+Payment;Third+party+Storages+and+Security" alt="Typing SVG" /> | ||
</p> | ||
<!-- markdownlint-enable MD033 MD041 --> | ||
|
||
**Backend Secrets** is a comprehensive collection of Python implementations covering various backend functionalities, organized into distinct modules. This repository is designed to serve as a one-stop resource for backend developers looking to streamline common tasks, enhance security, and optimize performance in their applications. Each folder addresses a specific area of backend development, from caching and authentication to machine learning and server scaling. | ||
|
||
## Directory Structure | ||
|
||
- **analytics**: Tools and libraries for tracking, analyzing, and visualizing application usage and metrics. | ||
- **apis**: Examples for implementing various API types, including REST, GraphQL, gRPC, and more. | ||
- **caching**: Different caching mechanisms like Redis, LRU, LFU, and file-based caching to improve application performance. | ||
- **clean_architecture**: Design principles and patterns for structuring Python applications in a maintainable and scalable way. | ||
- **database**: Implementations for connecting and interacting with multiple database types, including MySQL, PostgreSQL, MongoDB, Redis, and more. | ||
- **deployments**: Deployment scripts and tools for setting up and scaling applications across environments. | ||
- **docker**: Docker configurations to containerize services, making deployments easier and more consistent. | ||
- **emails**: Code examples for integrating with popular email services like AWS SES, Mailgun, and SendGrid. | ||
- **env_secrets**: Techniques for securely managing environment variables and sensitive data in Python applications. | ||
- **IaC (Infrastructure as Code)**: Scripts for automating infrastructure provisioning and management using tools like Terraform and CloudFormation. | ||
- **logging**: Logging solutions for tracking application events, errors, and performance metrics. | ||
- **machine_learning**: Modules for integrating machine learning models and handling tasks related to data processing and predictions. | ||
- **monitoring**: Tools for tracking system and application performance, including Prometheus, Grafana, and Datadog integrations. | ||
- **payments**: Implementations for handling payments with various providers such as Stripe, PayPal, and local options like M-Pesa. | ||
- **queueing**: Message queue implementations with RabbitMQ, Redis Queue, and Celery for handling background tasks. | ||
- **scaling**: Techniques and tools to scale Python applications effectively, including load balancing and horizontal scaling. | ||
- **security**: Security features such as encryption, authentication, rate limiting, and best practices for securing APIs. | ||
- **sms**: Code for sending SMS using providers like Twilio, Nexmo, AWS SNS, and others. | ||
- **storage**: Integrations with cloud storage providers like AWS S3, Google Cloud Storage, and Azure Blob. | ||
|
||
## Getting Started | ||
|
||
1. **Clone the repository**: | ||
```bash | ||
git clone https://github.com/<your-username>/backend-secrets.git | ||
cd backend-secrets | ||
``` | ||
|
||
2. **Install Dependencies**: Each folder contains instructions for installing necessary libraries. You can also create a virtual environment and install dependencies separately for each module. | ||
|
||
3. **Run Examples**: Navigate to the desired module and follow the instructions in its README to run specific examples. | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! If you have a feature to add, a bug to fix, or an improvement suggestion, please submit a pull request with a description of the changes. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Security | ||
|
||
As for the security, I personally think we will opt into the best practices for securing our backend services. Please if anyone has any suggestions kindly raise an issue or email me at `[email protected]`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Analytics | ||
|
||
This folder contains Python implementations for integrating various analytics tools into backend applications. Each script provides functions to send events, track metrics, and monitor application usage using different analytics platforms. | ||
|
||
## AWS CloudWatch | ||
|
||
AWS CloudWatch is a monitoring and observability service from AWS that allows you to collect and track metrics, set alarms, and automatically respond to changes in AWS resources. | ||
|
||
- **File**: `aws_cloudwatch_analytics.py` | ||
- **Setup**: | ||
1. Install the AWS SDK: `pip install boto3`. | ||
2. Configure AWS credentials with access to CloudWatch. | ||
|
||
- **Example Usage**: | ||
```python | ||
from aws_cloudwatch_analytics import put_custom_metric | ||
put_custom_metric("MyAppNamespace", "UserLogins", 1) | ||
``` | ||
|
||
## Azure Monitor | ||
|
||
Azure Monitor provides full-stack monitoring for applications, infrastructure, and network. It includes features like metrics tracking, alerting, and visualization. | ||
|
||
- **File**: `azure_monitor_analytics.py` | ||
- **Setup**: | ||
1. Install Azure SDK: `pip install azure-monitor-query azure-identity`. | ||
2. Configure Azure credentials (client ID, tenant ID, and client secret) for authentication. | ||
|
||
- **Example Usage**: | ||
```python | ||
from azure_monitor_analytics import query_metrics | ||
query_metrics("<resource_id>") | ||
``` | ||
|
||
## Google Analytics | ||
|
||
Google Analytics allows you to track website and application usage using events, page views, and other metrics through the Measurement Protocol. | ||
|
||
- **File**: `google_analytics.py` | ||
- **Setup**: | ||
1. No additional installation required, but you’ll need a Google Analytics tracking ID. | ||
|
||
- **Example Usage**: | ||
```python | ||
from google_analytics import send_event | ||
send_event("category", "action", "label", 10) | ||
``` | ||
|
||
## Mixpanel | ||
|
||
Mixpanel is an advanced analytics tool focused on tracking user interactions and product usage to provide insights into how users engage with your application. | ||
|
||
- **File**: `mixpanel_analytics.py` | ||
- **Setup**: | ||
1. Install the Mixpanel client: `pip install mixpanel`. | ||
|
||
- **Example Usage**: | ||
```python | ||
from mixpanel_analytics import track_event | ||
track_event("UserSignUp", "user_123", {"plan": "premium"}) | ||
``` | ||
|
||
## Sentry | ||
|
||
Sentry is primarily an error tracking tool, but it also provides application performance monitoring. It’s ideal for capturing and reporting exceptions in real-time. | ||
|
||
- **File**: `sentry_analytics.py` | ||
- **Setup**: | ||
1. Install the Sentry SDK: `pip install sentry-sdk`. | ||
2. Initialize Sentry with your project’s DSN. | ||
|
||
- **Example Usage**: | ||
```python | ||
from sentry_analytics import log_error | ||
log_error() | ||
``` | ||
|
||
## How to Use | ||
|
||
1. Clone the repository and navigate to the `analytics` folder. | ||
2. Install any required dependencies as mentioned in each section. | ||
3. Configure your credentials for each service (e.g., AWS access keys, Google Analytics tracking ID). | ||
4. Run the scripts to integrate analytics tracking into your application. | ||
|
||
## Contributing | ||
|
||
Feel free to contribute by adding more analytics tools or improving existing ones. Please submit a pull request with a detailed description of your changes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
|
||
import boto3 | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
AWS_REGION = os.getenv('AWS_REGION') | ||
|
||
# Initialize CloudWatch client | ||
cloudwatch = boto3.client('cloudwatch', region_name=AWS_REGION) | ||
|
||
|
||
def put_custom_metric(namespace, metric_name, value): | ||
response = cloudwatch.put_metric_data( | ||
Namespace=namespace, | ||
MetricData=[ | ||
{ | ||
'MetricName': metric_name, | ||
'Value': value, | ||
'Unit': 'Count' | ||
}, | ||
] | ||
) | ||
print(f"Metric sent: {metric_name} - Value: {value}") | ||
|
||
|
||
# Example usage | ||
put_custom_metric("MyAppNamespace", "UserLogins", 1) |
Oops, something went wrong.