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.4.4-cp313-cp313-win_amd64.whl (595.9 kB view details)

Uploaded CPython 3.13Windows x86-64

bosa_core_binary-0.4.4-cp313-cp313-manylinux_2_36_x86_64.whl (904.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.36+ x86-64

bosa_core_binary-0.4.4-cp313-cp313-manylinux_2_31_x86_64.whl (904.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.4.4-cp313-cp313-macosx_14_0_arm64.whl (632.2 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

bosa_core_binary-0.4.4-cp313-cp313-macosx_13_0_x86_64.whl (709.7 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

bosa_core_binary-0.4.4-cp312-cp312-win_amd64.whl (597.5 kB view details)

Uploaded CPython 3.12Windows x86-64

bosa_core_binary-0.4.4-cp312-cp312-manylinux_2_36_x86_64.whl (901.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.36+ x86-64

bosa_core_binary-0.4.4-cp312-cp312-manylinux_2_31_x86_64.whl (904.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.4.4-cp312-cp312-macosx_14_0_arm64.whl (630.9 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

bosa_core_binary-0.4.4-cp312-cp312-macosx_13_0_x86_64.whl (706.4 kB view details)

Uploaded CPython 3.12macOS 13.0+ x86-64

bosa_core_binary-0.4.4-cp311-cp311-win_amd64.whl (596.8 kB view details)

Uploaded CPython 3.11Windows x86-64

bosa_core_binary-0.4.4-cp311-cp311-manylinux_2_36_x86_64.whl (802.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.36+ x86-64

bosa_core_binary-0.4.4-cp311-cp311-manylinux_2_31_x86_64.whl (815.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.31+ x86-64

bosa_core_binary-0.4.4-cp311-cp311-macosx_14_0_arm64.whl (623.8 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

bosa_core_binary-0.4.4-cp311-cp311-macosx_13_0_x86_64.whl (696.9 kB view details)

Uploaded CPython 3.11macOS 13.0+ x86-64

File details

Details for the file bosa_core_binary-0.4.4-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.4.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4361e289b3370f58cdeb0cd22f8192b8768b26d9fe4796c62dede131ee065dee
MD5 bcd2b4725f06ef176abda3aa7757986e
BLAKE2b-256 b71c0b898ff6fa219cdc1aa424c05d72c030e1f5534187d35d889dece81607c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.4.4-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.4.4-cp313-cp313-manylinux_2_36_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.4.4-cp313-cp313-manylinux_2_36_x86_64.whl
Algorithm Hash digest
SHA256 74ebb9d213356a442d62f3c7140be6acb810d61b295c6c86b590277e1bccb630
MD5 ba7806ca90946cd6ec97edce200becaa
BLAKE2b-256 5911199f38d8968a9d4d262c138f24336e0a2e83b33338eee9a5c1cd4abe7a42

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.4.4-cp313-cp313-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.4.4-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 64d8d94d82ee8c6d3ea5cab7d3b4598ea6250a3b10d139103c79ee54ebd35b2e
MD5 090d1f27e8d0227fe3e1ae286f4c9244
BLAKE2b-256 a4e829331266730392c346dd858966ce2025d1b122a6caf76789fe28ec0cca01

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.4.4-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.4.4-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bf27ce5ea2c958d774e1b48c33c39c03b1d364dd6250232b226b2e7c889c4aef
MD5 fa32a5fadf7b0d95c453792e9ce43a7c
BLAKE2b-256 797f53fb9c3e412de3bee978e1051dd283bbfa387016f83a456ddcd1e46beada

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.4.4-cp313-cp313-macosx_14_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.4.4-cp313-cp313-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.4.4-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 b2ea780c3d108bfae6b0ccc86286786a165562789e6857d0850f21e434531064
MD5 9b446f590da84576c012b3ee0d88913c
BLAKE2b-256 e72fbfcd19b18842e57676943e5543dc522ced280116b4bfa538fa7e438a718a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.4.4-cp313-cp313-macosx_13_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.4.4-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.4.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 37b682506793fd8cf346d76bea8ea21ba4dec3fdbd61b476c936fa0928bd2119
MD5 c1765a131e66ba3be84609513dd36815
BLAKE2b-256 3ac75026f3d4b9f8124afdfd593ebb70f971377c5206a3f0d7e86a782f67da91

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.4.4-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.4.4-cp312-cp312-manylinux_2_36_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.4.4-cp312-cp312-manylinux_2_36_x86_64.whl
Algorithm Hash digest
SHA256 179f1338ec33ff9fc4a61e05ee3399463ee2e10f2015e4139c94f8628a759b53
MD5 596ec5a77b99b244e47bb650468fbc6f
BLAKE2b-256 67952655854594c98a0763ca9c47036df3e799c6448e015dd0f0530af3601232

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.4.4-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.4.4-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 5154c558bc4edca2af1ca021033cde18eb0d98f237b48b415a835dde923b76f2
MD5 179949c6814231db9ce07e86e9ae7808
BLAKE2b-256 8161af36115f843f36f7770cd55bb5a00ea51015cb40588d47b34d4ea14cba3a

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.4.4-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.4.4-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a207a64ca4221803f26c31cdf4f4631129c76ae7ab2fc1446166fcac02cbad89
MD5 b423686fada23879d74f5c72fb26c092
BLAKE2b-256 0105b743ff333b3ff51fcc0b67edb4bf984b0745a66cf49f4c463ed55dc7a39f

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.4.4-cp312-cp312-macosx_14_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.4.4-cp312-cp312-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.4.4-cp312-cp312-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 71b28303d13cdfa7933d00cf1261bdeafab8a25247db5bc99e800f4575249e4f
MD5 b6fe12be785d4dca3b64883c864b1fa9
BLAKE2b-256 cacd31ad65e8a664fb11537ed4f7a87eef908db8d6dd0e52392eb9462606c3ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.4.4-cp312-cp312-macosx_13_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.4.4-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.4.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ca663b92e0dd32b5b176f9880340f5ac8e44038652992453fa8e46c03ca8c0d8
MD5 0a9ac57cb5317ead0486784c6923dadb
BLAKE2b-256 799d2a1aec34d2822adf4ddfc0cd995485eeb4dce67c60d72f96b51584bffa77

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.4.4-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.4.4-cp311-cp311-manylinux_2_36_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.4.4-cp311-cp311-manylinux_2_36_x86_64.whl
Algorithm Hash digest
SHA256 e1bd028e1562893a6a6668180cc8228d10b443becdee1367f349840775b5e560
MD5 9fdd04dbdcb0c3db5ad18e5986a6ea6f
BLAKE2b-256 48de069c27719c97975bab239931b8ac70efedd27a52e3094cfdf6e8a1587557

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.4.4-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.4.4-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 86cbcd3ba508eaa2266a8f3c117b20680ab89f85951f85eae6fded801d6ce980
MD5 4bd1d3c1218db2403189cb35bd47667d
BLAKE2b-256 2d94a5694465e3197238fccd09546432ef7a6ae8593b283f41f3aa1feed0394a

See more details on using hashes here.

File details

Details for the file bosa_core_binary-0.4.4-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.4.4-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 cc7d070990c01aee6b08f256b8d4d3839982b0013f91895e56304a8319b8a2ce
MD5 aed4501148f8468275aa4cd19d8725c4
BLAKE2b-256 292875822a8c8f14581ad06d9f41e8dd63e93e315148385266a3faeb598404a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.4.4-cp311-cp311-macosx_14_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.4.4-cp311-cp311-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for bosa_core_binary-0.4.4-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 6e6678aedb9fd9526786e5b5105ca1b35361642d83d76c3b69adec1734e6f3e3
MD5 b8ddc524ff3db4724b8f018a5bb4c266
BLAKE2b-256 c94966a5103509aa0bbdc07cabe1f92acfb49ba2fc36232baae967f82a23195a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bosa_core_binary-0.4.4-cp311-cp311-macosx_13_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.

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