Name | service-linker JSON |
Version |
0.0.0a0
JSON |
| download |
home_page | None |
Summary | A simple Python library to manage kinds of services connections |
upload_time | 2025-01-16 01:45:47 |
maintainer | None |
docs_url | None |
author | None |
requires_python | None |
license | MIT License Copyright (c) 2024 ZhuJiaDong 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. |
keywords |
services
manage
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Service Linker Library
## Overview
The **Service Linker** library provides a unified and extensible way to manage connections to various services like databases, message brokers, and search engines. It simplifies connection management by ensuring proper lifecycle handling, thread-safety, and flexibility for different service requirements.
The core functionality includes:
- Registering service adapters for various services.
- Managing both thread-safe and non-thread-safe connections.
- Providing context management for connections.
## Key Features
1. **Extensibility**: Easily register new services by creating adapters.
2. **Thread-Safety**: Handle both thread-safe and non-thread-safe connections.
3. **Connection Lifecycle Management**: Automatically close all connections at program exit.
4. **Context Management**: Simplify connection handling using Python’s `with` statement.
## Components
### `core.py`
The `core.py` module provides the main `ServiceManager` class, which handles connection registration, retrieval, and cleanup.
#### Key Classes
1. **`ServiceManager`**
- Manages connections and ensures proper lifecycle handling.
- Supports both global and thread-local connection storage.
- Provides methods to register adapters, retrieve connections, and close connections.
2. **`ConnectionWrapper`**
- Wraps individual connections to provide additional management capabilities.
- Delegates attribute and method access to the underlying connection object.
### `adapter.py`
The `adapter.py` module defines the abstract base class `ServiceAdapter`, which must be implemented for each new service. It ensures consistency and enforces the implementation of methods to establish and close connections.
#### Key Methods
- `do_get_connection`: Establishes a connection.
- `do_close`: Closes a connection.
### Adapters
The library includes several pre-built adapters for popular services:
1. **Elasticsearch** (`adapters/elasticsearch_adapter.py`)
- Adapter: `ElasticSearchAdapter`
- Thread-Safe: Yes
2. **Kafka Consumer** (`adapters/kafka_consumer_adapter.py`)
- Adapter: `KafkaConsumerAdapter`
- Thread-Safe: No
3. **Kafka Producer** (`adapters/kafka_producer_adapter.py`)
- Adapter: `KafkaProducerAdapter`
- Thread-Safe: Yes
4. **MongoDB** (`adapters/mongo_adapter.py`)
- Adapter: `MongoAdapter`
- Thread-Safe: Yes
5. **MySQL (Raw)** (`adapters/mysql_raw_adapter.py`)
- Adapter: `MySQLRawAdapter`
- Thread-Safe: No
## Usage
### 1. Registering an Adapter
Adapters are registered automatically using the `@ServiceManager.register_service_adapter` decorator.
### 2. Retrieving a Connection
```python
from service_linker.core import ServiceManager
connection = ServiceManager.get_connection("elasticsearch", hosts=["http://localhost:9200"])
```
### 3. Using Context Management
```python
from service_linker.core import ServiceManager
with ServiceManager.connection_context("mongo", host="localhost", port=27017) as conn:
db = conn.my_database
print(db.list_collection_names())
```
### 4. Closing Connections
```python
from service_linker.core import ServiceManager
ServiceManager.close_connection("elasticsearch", hosts=["http://localhost:9200"])
```
### 5. Closing All Connections
All connections are automatically closed when the program exits, but you can manually invoke it:
```python
from service_linker.core import ServiceManager
ServiceManager.close_all_connections()
```
## Extending the Library
To add support for a new service, create a new adapter by subclassing `ServiceAdapter`:
```python
from service_linker.adapter import ServiceAdapter
from service_linker.core import ServiceManager
@ServiceManager.register_service_adapter
class MyServiceAdapter(ServiceAdapter):
thread_safe = True
service_name = "my_service"
def do_get_connection(self, **params):
# Logic to establish a connection
return connection
def do_close(self, connection):
# Logic to close the connection
pass
```
## Installation
Clone the repository and install dependencies:
```bash
pip install service_linker
```
## License
This project is licensed under the MIT License. See the LICENSE file for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "service-linker",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "services manage",
"author": null,
"author_email": "zjd-melo <zhujiadong.melo@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/79/2a/aa1de0aa813f1bd7c5ab16712f10fee1cccaca724c9ee47516ce0fe1c662/service_linker-0.0.0a0.tar.gz",
"platform": null,
"description": "# Service Linker Library\n\n## Overview\n\nThe **Service Linker** library provides a unified and extensible way to manage connections to various services like databases, message brokers, and search engines. It simplifies connection management by ensuring proper lifecycle handling, thread-safety, and flexibility for different service requirements.\n\nThe core functionality includes:\n\n- Registering service adapters for various services.\n- Managing both thread-safe and non-thread-safe connections.\n- Providing context management for connections.\n\n## Key Features\n\n1. **Extensibility**: Easily register new services by creating adapters.\n2. **Thread-Safety**: Handle both thread-safe and non-thread-safe connections.\n3. **Connection Lifecycle Management**: Automatically close all connections at program exit.\n4. **Context Management**: Simplify connection handling using Python\u2019s `with` statement.\n\n## Components\n\n### `core.py`\n\nThe `core.py` module provides the main `ServiceManager` class, which handles connection registration, retrieval, and cleanup.\n\n#### Key Classes\n\n1. **`ServiceManager`**\n - Manages connections and ensures proper lifecycle handling.\n - Supports both global and thread-local connection storage.\n - Provides methods to register adapters, retrieve connections, and close connections.\n\n2. **`ConnectionWrapper`**\n - Wraps individual connections to provide additional management capabilities.\n - Delegates attribute and method access to the underlying connection object.\n\n### `adapter.py`\n\nThe `adapter.py` module defines the abstract base class `ServiceAdapter`, which must be implemented for each new service. It ensures consistency and enforces the implementation of methods to establish and close connections.\n\n#### Key Methods\n\n- `do_get_connection`: Establishes a connection.\n- `do_close`: Closes a connection.\n\n### Adapters\n\nThe library includes several pre-built adapters for popular services:\n\n1. **Elasticsearch** (`adapters/elasticsearch_adapter.py`)\n - Adapter: `ElasticSearchAdapter`\n - Thread-Safe: Yes\n\n2. **Kafka Consumer** (`adapters/kafka_consumer_adapter.py`)\n - Adapter: `KafkaConsumerAdapter`\n - Thread-Safe: No\n\n3. **Kafka Producer** (`adapters/kafka_producer_adapter.py`)\n - Adapter: `KafkaProducerAdapter`\n - Thread-Safe: Yes\n\n4. **MongoDB** (`adapters/mongo_adapter.py`)\n - Adapter: `MongoAdapter`\n - Thread-Safe: Yes\n\n5. **MySQL (Raw)** (`adapters/mysql_raw_adapter.py`)\n - Adapter: `MySQLRawAdapter`\n - Thread-Safe: No\n\n## Usage\n\n### 1. Registering an Adapter\n\nAdapters are registered automatically using the `@ServiceManager.register_service_adapter` decorator.\n\n### 2. Retrieving a Connection\n\n```python\nfrom service_linker.core import ServiceManager\n\nconnection = ServiceManager.get_connection(\"elasticsearch\", hosts=[\"http://localhost:9200\"])\n```\n\n### 3. Using Context Management\n\n```python\nfrom service_linker.core import ServiceManager\n\nwith ServiceManager.connection_context(\"mongo\", host=\"localhost\", port=27017) as conn:\n db = conn.my_database\n print(db.list_collection_names())\n```\n\n### 4. Closing Connections\n\n```python\nfrom service_linker.core import ServiceManager\n\nServiceManager.close_connection(\"elasticsearch\", hosts=[\"http://localhost:9200\"])\n```\n\n### 5. Closing All Connections\n\nAll connections are automatically closed when the program exits, but you can manually invoke it:\n\n```python\nfrom service_linker.core import ServiceManager\n\nServiceManager.close_all_connections()\n```\n\n## Extending the Library\n\nTo add support for a new service, create a new adapter by subclassing `ServiceAdapter`:\n\n```python\nfrom service_linker.adapter import ServiceAdapter\nfrom service_linker.core import ServiceManager\n\n@ServiceManager.register_service_adapter\nclass MyServiceAdapter(ServiceAdapter):\n thread_safe = True\n service_name = \"my_service\"\n\n def do_get_connection(self, **params):\n # Logic to establish a connection\n return connection\n\n def do_close(self, connection):\n # Logic to close the connection\n pass\n```\n\n## Installation\n\nClone the repository and install dependencies:\n\n```bash\npip install service_linker\n```\n\n## License\n\nThis project is licensed under the MIT License. See the LICENSE file for details.\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 ZhuJiaDong 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. ",
"summary": "A simple Python library to manage kinds of services connections",
"version": "0.0.0a0",
"project_urls": {
"Homepage": "https://github.com/zjd-melo/service_linker",
"Issues": "https://github.com/zjd-melo/service_linker/issues",
"Repository": "https://github.com/zjd-melo/service_linker.git"
},
"split_keywords": [
"services",
"manage"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c7e22ba740140630376d40fb30b52b99804fd79912a0b931bd9ce85df27bea13",
"md5": "e666c31b142b9f5d36b32147147ec3f0",
"sha256": "f1ca8070a9f3aa9ce6508e6634b0dd15fa5578b5ed52078015c9455b53782645"
},
"downloads": -1,
"filename": "service_linker-0.0.0a0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e666c31b142b9f5d36b32147147ec3f0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 7880,
"upload_time": "2025-01-16T01:45:45",
"upload_time_iso_8601": "2025-01-16T01:45:45.404167Z",
"url": "https://files.pythonhosted.org/packages/c7/e2/2ba740140630376d40fb30b52b99804fd79912a0b931bd9ce85df27bea13/service_linker-0.0.0a0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "792aaa1de0aa813f1bd7c5ab16712f10fee1cccaca724c9ee47516ce0fe1c662",
"md5": "da07947f72da7fe37a54874b3c40fa8d",
"sha256": "36983659a76330a583f614d61909ff1945b5ed614546a65d93c8081481a854ba"
},
"downloads": -1,
"filename": "service_linker-0.0.0a0.tar.gz",
"has_sig": false,
"md5_digest": "da07947f72da7fe37a54874b3c40fa8d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7283,
"upload_time": "2025-01-16T01:45:47",
"upload_time_iso_8601": "2025-01-16T01:45:47.293290Z",
"url": "https://files.pythonhosted.org/packages/79/2a/aa1de0aa813f1bd7c5ab16712f10fee1cccaca724c9ee47516ce0fe1c662/service_linker-0.0.0a0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-16 01:45:47",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "zjd-melo",
"github_project": "service_linker",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "service-linker"
}