bw-essentials
Here’s a rephrased version of your description with improved flow and clarity:
bw-essentials is a Python utility package offering modular and production-ready wrappers for core infrastructure tasks. It simplifies operations such as AWS S3 interactions, email notifications, and version-controlled data lake workflows using LakeFS. Designed for flexibility and ease of integration, it's well-suited for use across microservices, data pipelines, and automation frameworks.
In addition to infrastructure utilities, it also includes service-specific wrappers for:
- Master Data
- Market Pricer
- Broker
- Model Portfolio Reporting
- Trade Placement
- User Portfolio
- User Portfolio Reporting
- Portfolio Business (payment-gateway configuration)
- Portfolio Product (Django content and catalogue APIs)
ApiClient
Synchronous ApiClient requests default to a 30-second timeout; pass timeout= to _request to override it per call.
Portfolio Business client
PortfolioBusiness fetches an analyst's payment-gateway configuration using
service-to-service authentication. Configure PORTFOLIO_BUSINESS_BASE_URL as
the service origin (without /business/portfolio) and set
PORTFOLIO_BUSINESS_API_KEY; the client sends the key as X-API-Key.
from bw_essentials.services.portfolio_business import PortfolioBusiness
client = PortfolioBusiness(service_user="payment-service")
gateway_config = client.get_payment_gateway_secrets("analyst-id")
Response credentials are redacted from HTTP logs.
Portfolio Product client
PortfolioProduct covers the Django content and catalogue APIs. Configure
PORTFOLIO_PRODUCT_BASE_URL as the service root (for example,
http://host:8000/portfolio-product) and use set_tenant_id() for tenant
selection; an unknown tenant falls back to the server default. Requests and
responses use snake_case, and methods return the unwrapped response data.
HTTP errors and missing data keys propagate to callers, while response bodies
are redacted from logs.
The server returns HTTP 404 for empty rebalance or subscription history.
Subscription plan_notes must be an object or an array, and portfolio
exchange should be supplied because its database column is NOT NULL even
though validation marks it optional. The existing PortfolioContent and
PortfolioCatalogue clients remain unchanged for the Node services.
from bw_essentials.services.portfolio_product import PortfolioProduct
client = PortfolioProduct(service_user="recommendations-api")
client.set_tenant_id("ysl")
portfolios = client.list_portfolios(status="active", broker="ysl")
📦 Installation
pip install bw-essentials
📁 S3Utils
S3Utils provides a high-level interface to interact with AWS S3 and S3-compatible services like MinIO or LocalStack.
🔧 Initialization
from bw_essentials.s3_utils import S3Utils
s3 = S3Utils()
✅ Available Methods
| Method | Description |
|---|---|
upload_file(bucket, key, file_path) |
Upload a local file to S3 |
download_file(bucket, key, dest_path) |
Download a file from S3 |
list_files(bucket, prefix="") |
List all files under a prefix |
read_file(bucket, key) |
Read and return the content of a file |
delete_file(bucket, key) |
Delete a specific file |
file_exists(bucket, key) |
Check if a file exists |
get_latest_file(bucket, prefix) |
Get the latest file by modified time |
sync_local_to_s3(bucket, prefix, local_path) |
Recursively upload a local directory to S3 |
sync_s3_to_local(bucket, prefix, local_path) |
Recursively download an S3 prefix to local |
generate_presigned_url(bucket_name, object_key, expiration) |
Generates Pre Signed Url for given S3 Object. |
📬 EmailClient
EmailClient helps send email notifications with or without attachments using any SMTP server.
🔧 Initialization
from bw_essentials.email_client import EmailClient
client = EmailClient(
sender_email="noreply@example.com",
sender_name="BW Notifier"
)
✅ Available Methods
| Method | Description |
|---|---|
send_email_without_attachment(to_addresses, cc_addresses, subject, body, is_html=True) |
Send an email without attachment |
send_email_with_attachment(to_addresses, cc_addresses, subject, body, attachment_path, is_html=True) |
Send an email with a file attachment |
- Supports both plain text and HTML.
- Accepts single or multiple recipients (
strorList[str]). - Gracefully handles invalid paths and logs detailed errors.
🏞️ DataLoch (LakeFS Wrapper)
DataLoch wraps LakeFS Python client for working with versioned data over S3. Useful for managing commits, branches, and file operations in a data lake.
🔧 Initialization
from bw_essentials.data_loch import LakeFS
dl = LakeFS()
You can pass branch and repo to individual methods or initialize them via dl.repo = "repo" and dl.branch = "branch".
✅ Available Methods
| Method | Description |
|---|---|
upload_file(local_path, repo, branch, dest_path) |
Upload a single file to a branch |
download_file(repo, branch, file_path, dest_path) |
Download a single file |
sync_local_to_lakefs(local_path, repo, branch, dest_prefix) |
Recursively upload a directory |
sync_lakefs_to_local(repo, branch, src_prefix, local_path) |
Recursively download a directory |
commit(repo, branch, message) |
Commit the current changes on a branch |
get_latest_file(repo, branch, prefix) |
Get latest file (by time) under a prefix |
delete_file(repo, branch, file_path) |
Delete a specific file |
- Supports S3-compatible object storage behind LakeFS.
- Handles versioning and commit messages for reproducibility.
🧪 Example Use Case
# Send notification with S3 report
from bw_essentials.s3_utils import S3Utils
from bw_essentials.email_client import EmailClient
s3 = S3Utils("AK", "SK")
file_path = "/tmp/report.csv"
s3.download_file("my-bucket", "reports/weekly.csv", file_path)
email_client = EmailClient("me@example.com", "Report Bot")
email_client.send_email_with_attachment(
to_addresses="client@example.com",
cc_addresses=["ops@example.com"],
subject="Weekly Report",
body="<h1>Attached is your report</h1>",
attachment_path=file_path
)
Here’s the updated setup.py with a module docstring and updated dependencies:
🔔 Notifications
Notifications helps send structured alerts and logs to external communication tools like Microsoft Teams and Zenduty. Ideal for operational awareness and incident response workflows.
🔧 Initialization
from bw_essentials.notifications import Notifications
notifier = Notifications(
title="BW Alerts",
summary="Pipeline Failure",
message="Daily data sync failed.",
webhook_url="https://sample.webhook.url"
)
✅ Available Methods
| Method | Description |
|---|---|
notify_message(message=None, summary=None, alert=False) |
Send a general log message to Teams |
notify_error(message=None, summary=None, alert=True, trace=None, request_id=None) |
Send an error alert to Teams and Zenduty |
- Automatically uses different formats for logs vs. alerts.
- Teams messages are sent via Adaptive Cards.
- Zenduty alerts include critical summaries and tracebacks.
- You can override the default
message,summary,trace, andrequest_idper notification.
📘 Example Use Case
notifier.notify_error(
message="ETL job failed due to timeout.",
summary="Job: daily-prices-sync",
trace="Traceback (most recent call last): ...",
request_id="req-123abc"
)
SigNoz Observability
OpenTelemetry dependencies are included in the core installation. The
observability extra remains available as a compatibility alias:
pip install "bw-essentials-core[observability]"
Django imports:
from bw_essentials.observability.django.otel import (
DjangoOTelService,
build_sanitized_request_context,
configure_celery_tracing,
configure_otel_logging,
init_otel,
)
FastAPI imports:
from bw_essentials.observability.fastapi.otel import (
FastAPIOTelService,
build_sanitized_fastapi_request_context,
init_fastapi_otel,
)
The observability helpers are split by framework: Django startup lives in
bw_essentials.observability.django.otel, FastAPI startup lives in
bw_essentials.observability.fastapi.otel, and common sanitization/export
utilities live in bw_essentials.observability.services.
These helpers provide idempotent OTel startup, trace-correlated log export, safe outbound HTTP span URLs without query strings, sanitized request-context helpers that can be called from each service's existing request middleware, and FastAPI instrumentation for requests/httpx/Redis/SQLAlchemy.
Let me know if you'd like a logo badge, GitHub Actions setup, or example .whl build as well.
📬 Contact
For bugs or feature requests, open an issue or contact support+tech@investorai.in
Metadata
Release files for bw-essentials-core 0.1.88
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bw_essentials_core-0.1.88.tar.gz | 152.6 kB | Without provenance | Details for bw_essentials_core-0.1.88.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bw_essentials_core-0.1.88-py3-none-any.whl | Python 3 | none | any | Details for bw_essentials_core-0.1.88-py3-none-any.whl |
Total release size: 296.8 kB
Release files / bw_essentials_core-0.1.88.tar.gz
| Download URL | bw_essentials_core-0.1.88.tar.gz |
|---|---|
| Size | 152.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
67f140a4f124ded6586796f4ce8d4b71de55e7c30cb5b8decfc991b21c896d04
|
|
BLAKE2b-256 checksum How to use checksums |
927984a49bdb6d287c18b26dd034397b36ddbb71200c0945dae51197e0d0af97
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.0
|
Release files / bw_essentials_core-0.1.88-py3-none-any.whl
| Download URL | bw_essentials_core-0.1.88-py3-none-any.whl |
|---|---|
| Size | 144.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
537fb40e04c4582e504cc0bf33f705bd486c892126a728a4bf720681fc8bf589
|
|
BLAKE2b-256 checksum How to use checksums |
8cf7a622b35e15efe562a888feb3c36c1afa725b8c6850e77ada1243aae243a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.0
|
Security for bw-essentials-core 0.1.88
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.