Skip to main content

BOSA Core Library

Project description

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

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

Plugin Architecture

How It Works

  1. Plugin Manager: The central piece that orchestrates everything

    • Manages plugin lifecycle
    • Handles service registration
    • Initializes plugins with required dependencies
  2. 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!
  3. 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)
  4. Plugin: Base class for all plugins

    • Has basic metadata (name, description, version)
    • Receives injected services automatically
    • Can be extended with specific functionality
  5. 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)
  6. 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.

  1. 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.
  2. 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>.
  3. 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.
  4. 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>

[!WARNING] If you are using Logger Ner API handler, the logging process may take some time because it needs to call an API for every log entry synchronously.

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

  1. Install dependencies:

    poetry install
    
  2. Create a plugin:

    class MyPlugin(Plugin):
        name = "my-plugin"
        description = "My awesome plugin"
        version = "1.0.0"
    
  3. 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.sh to perform all checks:
    • Code formatting and validation (ruff)
    • Documentation style (pydocstyle)
    • Tests (pytest)
    • And more!

References

Product Requirements Documents(PRD):

  • N/A

Architecture Documents:

Design Documents:

Implementation Documents:

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bosa_core_binary-0.5.2b1-cp313-cp313-win_amd64.whl (639.6 kB view details)

Uploaded CPython 3.13Windows x86-64

bosa_core_binary-0.5.2b1-cp313-cp313-manylinux_2_31_x86_64.whl (951.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.5.2b1-cp313-cp313-macosx_13_0_x86_64.macosx_15_0_x86_64.whl (733.1 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64macOS 15.0+ x86-64

bosa_core_binary-0.5.2b1-cp313-cp313-macosx_13_0_arm64.macosx_15_0_arm64.whl (638.7 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64macOS 15.0+ ARM64

bosa_core_binary-0.5.2b1-cp312-cp312-win_amd64.whl (643.7 kB view details)

Uploaded CPython 3.12Windows x86-64

bosa_core_binary-0.5.2b1-cp312-cp312-manylinux_2_31_x86_64.whl (952.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.5.2b1-cp312-cp312-macosx_13_0_x86_64.macosx_15_0_x86_64.whl (729.9 kB view details)

Uploaded CPython 3.12macOS 13.0+ x86-64macOS 15.0+ x86-64

bosa_core_binary-0.5.2b1-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl (637.5 kB view details)

Uploaded CPython 3.12macOS 13.0+ ARM64macOS 15.0+ ARM64

bosa_core_binary-0.5.2b1-cp311-cp311-win_amd64.whl (644.5 kB view details)

Uploaded CPython 3.11Windows x86-64

bosa_core_binary-0.5.2b1-cp311-cp311-manylinux_2_31_x86_64.whl (861.8 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.5.2b1-cp311-cp311-macosx_13_0_x86_64.macosx_15_0_x86_64.whl (721.4 kB view details)

Uploaded CPython 3.11macOS 13.0+ x86-64macOS 15.0+ x86-64

bosa_core_binary-0.5.2b1-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl (621.2 kB view details)

Uploaded CPython 3.11macOS 13.0+ ARM64macOS 15.0+ ARM64

File details

Details for the file bosa_core_binary-0.5.2b1-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.2b1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8a1fe2b5dbfb5018067a2eb9d8370c0d8998d826652de88a9dc6324828aa76e7
MD5 976ad735a7edf7b81b810ab5c96b6df8
BLAKE2b-256 ada8aa0b67b8c5331a8eeea864e97212dea119342a64f5bf3028e5d696656c43

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.2b1-cp313-cp313-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.2b1-cp313-cp313-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.2b1-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 a8de8e13b04efb3749f87bd75bb694e1f90389452d4141eb0b0ef843142dd209
MD5 d05fecadd41d5973d723b65b80faab02
BLAKE2b-256 006e17aa68ce99a48bb53f61cf4095ce57c47b32620032694620098a4473bde0

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.5.2b1-cp313-cp313-macosx_13_0_x86_64.macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.2b1-cp313-cp313-macosx_13_0_x86_64.macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 ebd170e8485f0fb9a58189be479de6e4849e2c3b5ef7ee21f7be2afcb25dcf06
MD5 57e12277be6f78073153db36f13214b6
BLAKE2b-256 a848c2e10fed8885a140f9713e8c01dffef1c8100535dccb999670ba0ca7d4ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.2b1-cp313-cp313-macosx_13_0_x86_64.macosx_15_0_x86_64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.2b1-cp313-cp313-macosx_13_0_arm64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.2b1-cp313-cp313-macosx_13_0_arm64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 904b45cede3aef8490c6289867de306677e94c76cc3148c4153a75c56f79faf7
MD5 2eda55c8ba364a7e0cd3dba3070025fc
BLAKE2b-256 9ea5952982f61cee39d9feb0230b12b5deed2830056ff2821d9b761a60eaccda

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.2b1-cp313-cp313-macosx_13_0_arm64.macosx_15_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.2b1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.2b1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 bdfaa183988a4d626ec961499aea2e3ed55c5edc7ab534daa8e71c46b9a08273
MD5 85ce6d8a3dabc083db05114ce99104b2
BLAKE2b-256 2e780f4c8069a078a953b4d5153ad2995c9857301738b3286c3cf7765e4cf35b

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.2b1-cp312-cp312-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.2b1-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.2b1-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 ba1be3bd693dff820a6ebacc91b48802c927b2894855ae7baf231d9bdbaa9d15
MD5 fe4c41d775c58ae2501f67ac4bd0a3a4
BLAKE2b-256 c0e984abadb0132603cc7ac4e245cffc5a4268649ddebe7da5a0dafde808efd5

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.5.2b1-cp312-cp312-macosx_13_0_x86_64.macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.2b1-cp312-cp312-macosx_13_0_x86_64.macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 0559fa9b3810b24ec770509153f65aa27eed9b0e6e53e3c93b703abc9e3ab0ad
MD5 5da4e1faa041aef9e082318bdaacdc65
BLAKE2b-256 5eabf3ce4197d5add100c4863866fec1449447b8c60e4e80d6830ffd302b1664

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.2b1-cp312-cp312-macosx_13_0_x86_64.macosx_15_0_x86_64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.2b1-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.2b1-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 76e4e1b933fcd82498ac28e20cd73a74dba0076af950f004d98e343ba23235f4
MD5 87b1341911425a6d09cde0aff5260a67
BLAKE2b-256 e58b0d6a1e0b2edf87243487fb73ada044e6ab9a8191a5657d817ba82b4afe5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.2b1-cp312-cp312-macosx_13_0_arm64.macosx_15_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.2b1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.2b1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f80bafdff0282cb70670c4d3662542cf05732362293e7667f3504f94e00b999c
MD5 546257a5b8bbd34b8ae667d92d3451e5
BLAKE2b-256 572fc6d8a46eaa860cb98cb75a65628d0d47647a7529fc6e6f3297daf401cee2

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.2b1-cp311-cp311-win_amd64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.2b1-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.2b1-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 9f88ad2f05dc5448e0e1c252a2bf2c133ade9fee3eeceb53e7a34651ed1ce1af
MD5 04967c47f397c92224f60f1d3564cd17
BLAKE2b-256 628f3431d06c131be8021b0c7d9df57d64195fbe2ef4ef7af5bf85b533bbaed1

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.5.2b1-cp311-cp311-macosx_13_0_x86_64.macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.2b1-cp311-cp311-macosx_13_0_x86_64.macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 a9f3fb0497f318ad258f6c9fea3155a14d0af767f95ad6a2355276cdfc68167e
MD5 ebdb8d33f895d8aef6aa00f35cdf2973
BLAKE2b-256 d7df2358e603d256792170c398510ae48c8e06df57059af7ff2c03de1a387e1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.2b1-cp311-cp311-macosx_13_0_x86_64.macosx_15_0_x86_64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bosa_core_binary-0.5.2b1-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.5.2b1-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 fff855575553bc5afe395f52f9542ebf5e715a6387b125b117fc69ec1002610a
MD5 e8c96e43df9cb8bab8163a24956d90f8
BLAKE2b-256 32626d69d7461dd47297e9ededf0c202b9fbe428a10edacb53861436292945fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.5.2b1-cp311-cp311-macosx_13_0_arm64.macosx_15_0_arm64.whl:

Publisher: build-binary.yml on GDP-ADMIN/bosa-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page