BOSA Core
BOSA Core is a flexible plugin-based architecture that allows you to build modular and extensible applications. It provides a robust framework for managing plugins, handling dependencies, and injecting services.
Key Features
- 🔌 Plugin-based Architecture
- 💉 Dependency Injection
- 🔄 Service Registry
- 🛠️ Flexible Plugin Handlers
- 🌐 HTTP Interface Support
- 📊 OpenTelemetry Integration
- 🛡️ Sentry Error Tracking
- 📜 Logging
Installation
Prerequisites
- Python 3.11+ - Install here
- Pip (if using Pip) - Install here
- Poetry 2.1.3+ (if using Poetry) - Install here
- Git (if using Git) - Install here
- For git installation:
- Access to the GDP Labs SDK github repository
1. Installation from Pypi
Choose one of the following methods to install the package:
Using pip
pip install bosa-core-binary
Using Poetry
poetry add bosa-core-binary
2. Development Installation (Git)
For development purposes, you can install directly from the Git repository:
poetry add "git+ssh://git@github.com/GDP-ADMIN/bosa-sdk.git#subdirectory=python/bosa-core"
Plugin Architecture Overview
How It Works
-
Plugin Manager: The central piece that orchestrates everything
- Manages plugin lifecycle
- Handles service registration
- Initializes plugins with required dependencies
-
Service Registry: A container for all services
- Stores service instances
- Handles dependency injection
- Maps service types to their implementations
- Note: You don't need to create your own Service Registry - it's integrated into the Manager!
-
Plugin Handler: Interface for providing services to plugins
- Creates service injections through
create_injections - Initializes plugin-specific resources
- Can be extended for different types of plugins (e.g., HTTP handlers)
- Creates service injections through
-
Plugin: Base class for all plugins
- Has basic metadata (name, description, version)
- Receives injected services automatically
- Can be extended with specific functionality
-
Open Telemetry: Initializer class to use open telemetry
- Integrates with OpenTelemetry for tracing and metrics
- Provides observability for plugins and services
- Can be configured to export data to various backends (e.g., Jaeger, Prometheus)
-
Sentry: Initializer class to use sentry
- Integrates with Sentry for error tracking and performance monitoring
- Captures exceptions and sends them to Sentry
- Provides insights into application performance and errors
Authentication
BOSA Core provides a robust, multi-tenancy authentication system, allowing secure client and user management.
-
Client Management:
- Clients are created using a Master Key (
BOSA_WHITELISTED_KEYS). - Each client has a unique API key used for authentication.
- API Key Format:
sk-client-<base64-client-id>.<base64-client-name>.<client-secret>. - Clients can manage their users and authentication settings.
- Clients are created using a Master Key (
-
User Authentication:
- Clients create users by providing an identifier.
- Each user receives a secret, which is displayed only once.
- Users authenticate using their identifier and secret.
- User API Key Format:
sk-user-<base64-user-id>.<base64-user-identifier>.<user-secret>.
-
Token-Based Access:
- Upon authentication, users receive JWT tokens for secure access.
- Tokens are verified for subsequent requests.
- Tokens expire after 30 days (default: 43,200 minutes).
- Tokens can be revoked when necessary.
-
Third-Party Integrations:
- Users can create integrations with third-party services.
- Authentication credentials are securely stored.
- Each integration can be assigned scoped access.
For detailed implementation, refer to the Authentication README.
Implementation Details
The plugin system works through these key components:
1. Plugin Manager
from fastapi_interface import FastApiHttpInterface
# Create FastAPI handler
fastapi_handler = FastApiHttpInterface()
# Initialize manager with the handler
manager = PluginManager(handlers=[fastapi_handler])
manager.register_plugin(MyPlugin)
- Initializes the plugin system
- Manages plugin lifecycle
- Handles service registration
2. Plugin Handler
from bosa_core.plugin import PluginHandler
class MyHandler(PluginHandler):
@classmethod
def create_injections(cls, instance):
# Tell the manager what services this handler provides
return {MyService: instance}
@classmethod
def initialize_plugin(cls, instance, plugin):
# Initialize plugin resources
pass
- Creates service mappings via
create_injections - Initializes plugin resources
- Can be customized for different plugin types
3. Plugin
from bosa_core.plugin import Plugin
from fastapi_interface import FastApiService
class MyPlugin(Plugin):
# Services will be injected automatically
fastapi_service: FastApiService
def __init__(self, name, description, version):
super().__init__(name, description, version)
- Base class for all plugins
- Receives injected services
- Can be extended with custom functionality
4. Open telemetry external exporter (enable fastapi & langchain instrumentation)
from bosa_core.telemetry import OpenTelemetryConfig, FastAPIConfig, init_telemetry
from fastapi import FastAPI
endpoint = "your-exporter-endpoint"
port = "your-exporter-port"
attributes = {
"key1":"val1"
}
app = FastAPI()
use_langchain_instrumentation = True
fastapi_config = FastAPIConfig(app=app)
otel_config = OpenTelemetryConfig(endpoint=endpoint, port=port, attributes=attributes, fastapi_config=fastapi_config, use_langchain=use_langchain_instrumentation)
init_telemetry(TelemetryConfig(otel_config=otel_config))
5. Sentry
from bosa_core.telemetry import SentryConfig, init_telemetry
def traces_sampler(sampling_context: dict) -> float:
"""Determine appropriate sampling rate for Sentry transactions.
Args:
sampling_context: Context dictionary containing transaction information
Returns:
float: Sampling rate between 0 and 1
"""
### you can use customization (ex: for certain name sampler will be 0.1) for trace_sampler in this class
return 1.0
dsn = "your-dsn"
environment = "development/staging/production"
release = "your release tag"
sentry_config = SentryConfig(
dsn=dsn,
environment=environment,
release=release,
traces_sampler=traces_sampler,
send_default_pii=True,
)
init_telemetry(TelemetryConfig(sentry_config=sentry_config))
6. Sentry with Open Telemetry (enable fastapi & langchain instrumentation)
from bosa_core.telemetry import SentryConfig, init_telemetry, FastAPIConfig, OpenTelemetryConfig
from fastapi import FastAPI
def traces_sampler(sampling_context: dict) -> float:
"""Determine appropriate sampling rate for Sentry transactions.
Args:
sampling_context: Context dictionary containing transaction information
Returns:
float: Sampling rate between 0 and 1
"""
### you can use customization (ex: for certain name sampler will be 0.1) for trace_sampler in this class
return 1.0
dsn = "your-dsn"
environment = "development/staging/production"
release = "your release tag"
attributes = {
"key1":"val1"
}
app = FastAPI()
use_langchain_instrumentation = True
fastapi_config = FastAPIConfig(app=app)
opentelemetry_init = OpenTelemetryConfig(attributes=attributes, fastapi_config=fastapi_config, use_langchain=use_langchain_instrumentation)
sentry_config = SentryConfig(
dsn=dsn,
environment=environment,
release=release,
traces_sampler=traces_sampler,
send_default_pii=True,
open_telemetry_initiliazer=opentelemetry_init
)
init_telemetry(sentry_config=sentry_config)
7. Logging Ner API Handler
from bosa_core.logger import init_ner_pii_logging_handler
init_ner_pii_logging_handler(logger_name="logging-name", api_url="https://dev-api-gdplabs-ner-api.obrol.id/anonymize", api_field="text", pii_ner_process_enabled=True)
logger.info("contoh nomor ktp 3525011212941001\ncontoh email john.doe@example.com\ncontoh nomor telepon +628121729819 dan 0812898029384.\ncontoh npwp 01.123.456.7-891.234" ) # if you using gdplabs ner API output will be contoh nomor ktp <ID_KTP_1>\ncontoh email <EMAIL_ADDRESS_1>\ncontoh nomor telepon <PHONE_NUMBER_1> dan <PHONE_NUMBER_2>.\ncontoh npwp <ID_NPWP_1>
8. Logging Regex Handler
from bosa_core.logger import init_regex_pii_logging_handler
init_regex_pii_logging_handler(logger_name="logging-name", pii_regex_process_enabled=True)
logger.info("contoh nomor ktp 3525011212941001\ncontoh email john.doe@example.com\ncontoh nomor telepon +628121729819 dan 0812898029384.\ncontoh npwp 01.123.456.7-891.234" ) # if you using gdplabs ner API output will be contoh nomor ktp <ID_KTP_1>\ncontoh email <EMAIL_ADDRESS_1>\ncontoh nomor telepon <PHONE_NUMBER_1> dan <PHONE_NUMBER_2>.\ncontoh npwp <ID_NPWP_1>
Getting Started
-
Install dependencies:
poetry install -
Create a plugin:
class MyPlugin(Plugin): name = "my-plugin" description = "My awesome plugin" version = "1.0.0"
-
Register and use:
# Using FastAPI as an example from fastapi import FastAPI from fastapi_interface import FastApiHttpInterface app = FastAPI() fastapi_handler = FastApiHttpInterface(app) manager = PluginManager(handlers=[fastapi_handler]) manager.register_plugin(MyPlugin)
Development
- Use Poetry for dependency management
- Install pre-commit hooks
poetry run pre-commit install. This will run checks before each commit. - Run
./build.local.shto perform all checks:- Code formatting and validation (
ruff) - Documentation style (pydocstyle)
- Tests (pytest)
- And more!
- Code formatting and validation (
References
Product Requirements Documents(PRD):
- N/A
Architecture Documents:
Design Documents:
Implementation Documents:
Metadata
Release files for bosa-core-binary 0.9.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 8.4 MB
Release files / bosa_core_binary-0.9.7-cp313-cp313-win_amd64.whl
| Download URL | bosa_core_binary-0.9.7-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 800.0 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
834c20184f59ccbf4f9559a3772da8eebdfa4f13554c01e40c02f537e6165a16
|
|
BLAKE2b-256 checksum How to use checksums |
f83ef1c9571ce9e076bfe90600c7845e8d2334db7014e849f7495bfe9ae61354
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 22, 2025.
Transparency logRelease files / bosa_core_binary-0.9.7-cp313-cp313-manylinux_2_31_x86_64.whl
| Download URL | bosa_core_binary-0.9.7-cp313-cp313-manylinux_2_31_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.13 Linux glibc 2.31+ x86-64 |
|
SHA-256 checksum How to use checksums |
d9cbdc4b58d8f7275c19bf9a2553fab4adc2754fd82effc10c90ce8b6ccd4a87
|
|
BLAKE2b-256 checksum How to use checksums |
e4646ea2a1e7ccbd193f32bf6eb139439925bb5dadde0d027776d0255fb4affb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.8.16
|
Release files / bosa_core_binary-0.9.7-cp313-cp313-macosx_13_0_arm64.whl
| Download URL | bosa_core_binary-0.9.7-cp313-cp313-macosx_13_0_arm64.whl |
|---|---|
| Size | 836.0 kB |
| Tags | CPython 3.13 macOS 13.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
bcaa06116ddc2e89431c5483cd299f1882c4c7e7f50642d3c9be441c19de8ad7
|
|
BLAKE2b-256 checksum How to use checksums |
17029ad65c7efe17b5799816cf0b1e8c69facca7fe6f4e74f7a556b9981f6cbb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 22, 2025.
Transparency logRelease files / bosa_core_binary-0.9.7-cp312-cp312-win_amd64.whl
| Download URL | bosa_core_binary-0.9.7-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 801.0 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
75a153635108da7bffdf20bb56d6b7d1f97151fb98b0dc1c67e6730c719d207c
|
|
BLAKE2b-256 checksum How to use checksums |
657d90dc403b3dd80aa20be9880e4b29597ceaf8880c5ecf6b9f41768b6540a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 22, 2025.
Transparency logRelease files / bosa_core_binary-0.9.7-cp312-cp312-manylinux_2_31_x86_64.whl
| Download URL | bosa_core_binary-0.9.7-cp312-cp312-manylinux_2_31_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.12 Linux glibc 2.31+ x86-64 |
|
SHA-256 checksum How to use checksums |
8a74852412323b7294c4b6ceac24f5ad3e867400c35d21c7031b318da1588b1e
|
|
BLAKE2b-256 checksum How to use checksums |
ba5f7cf3fab374fb513ca4fabb219e7c275c4106b8e96d5d64dcdb536158f088
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.8.16
|
Release files / bosa_core_binary-0.9.7-cp312-cp312-macosx_13_0_arm64.whl
| Download URL | bosa_core_binary-0.9.7-cp312-cp312-macosx_13_0_arm64.whl |
|---|---|
| Size | 831.1 kB |
| Tags | CPython 3.12 macOS 13.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
c8f22e19da834002e8897522be1b51747882bf3fd92c9fa11457d39693c643c6
|
|
BLAKE2b-256 checksum How to use checksums |
14d5c9b2187d2cfdfd699199a7291c699415b3dc8c4a89e123078fd93c7f8512
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 22, 2025.
Transparency logRelease files / bosa_core_binary-0.9.7-cp311-cp311-win_amd64.whl
| Download URL | bosa_core_binary-0.9.7-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 815.4 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
480fde91063353e76d27536f0f28938fc66f0af617d5ae4a85ab4d33d52b36d4
|
|
BLAKE2b-256 checksum How to use checksums |
589f9eabcba7d29703c9afa0d14765e643ac187c91edcaec886c33adcc084a01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 22, 2025.
Transparency logRelease files / bosa_core_binary-0.9.7-cp311-cp311-manylinux_2_31_x86_64.whl
| Download URL | bosa_core_binary-0.9.7-cp311-cp311-manylinux_2_31_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.11 Linux glibc 2.31+ x86-64 |
|
SHA-256 checksum How to use checksums |
91feb615751ba27efb385b43075d6e8cbc49a7b1033125bf063ae0053b203ace
|
|
BLAKE2b-256 checksum How to use checksums |
9a1af13de5290e27a42d04ee2837bcc23c44c64b6c510b04560be31126707a09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.8.16
|
Release files / bosa_core_binary-0.9.7-cp311-cp311-macosx_13_0_arm64.whl
| Download URL | bosa_core_binary-0.9.7-cp311-cp311-macosx_13_0_arm64.whl |
|---|---|
| Size | 810.4 kB |
| Tags | CPython 3.11 macOS 13.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
3c447d6542520f139260e54a8a00c47082ee3ad3f7cf07cb6fb8b0e1de3fa2b5
|
|
BLAKE2b-256 checksum How to use checksums |
684c08682f5d983ad8fcaea3915258cf483e6097ff6aa5784c009ba552b508c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 22, 2025.
Transparency log