inter-service-sdk


Nameinter-service-sdk JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/AlexanderRyzhko/inter-service-sdk
SummaryComplete framework for inter-service communication with client, server utilities, auth and encryption
upload_time2025-10-06 18:46:08
maintainerNone
docs_urlNone
authorBlazel
requires_python>=3.8
licenseNone
keywords http client server api rest fastapi inter-service microservices authentication encryption ecc bearer-token
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Inter-Service SDK

Generic HTTP client for secure service-to-service communication with bearer token authentication and optional ECC encryption.

## Features

- 🔐 **Bearer Token Auth** - Automatic authentication headers
- 🔒 **Optional ECC Encryption** - End-to-end encryption for sensitive data
- 🎯 **Path & Query Parameters** - Clean parameter substitution
- 🔄 **Automatic Retries** - Exponential backoff for failed requests
- 📝 **Structured Logging** - Request/response tracking
- 🚀 **Zero Dependencies** - Only requests and cryptography (optional)

## Installation

```bash
pip install inter-service-sdk
```

## Quick Start

```python
from inter_service_sdk import InterServiceClient

# Initialize client
client = InterServiceClient(
    base_url="https://api.example.com",
    api_key="your-secret-key"
)

# Make a request
response = client.request(
    endpoint="users/{user_id}",
    path_params={"user_id": 123}
)

print(response["data"])
```

## Usage

### Basic GET Request

```python
client = InterServiceClient(
    base_url="https://api.example.com",
    api_key="your-api-key"
)

# GET /api/v1/inter-service/users/123
user = client.request(
    endpoint="users/{user_id}",
    path_params={"user_id": 123}
)
```

### With Query Parameters

```python
# GET /api/v1/inter-service/users/search?q=john&type=email&limit=10
results = client.request(
    endpoint="users/search",
    query_params={
        "q": "john",
        "type": "email",
        "limit": 10
    }
)
```

### POST Request

```python
# POST /api/v1/inter-service/users
new_user = client.request(
    endpoint="users",
    method="POST",
    data={
        "name": "John Doe",
        "email": "john@example.com"
    }
)
```

### With ECC Encryption

```python
client = InterServiceClient(
    base_url="https://api.example.com",
    api_key="your-api-key",
    ecc_private_key=os.getenv("PRIVATE_KEY"),
    ecc_public_key=os.getenv("PUBLIC_KEY")
)

# Auto-decrypt response
credentials = client.request(
    endpoint="credentials/{id}",
    path_params={"id": 456},
    decrypt=True
)

# Auto-encrypt request
client.request(
    endpoint="secrets",
    method="POST",
    data={"secret": "sensitive data"},
    encrypt=True
)
```

### Custom API Prefix

```python
# Default prefix: /api/v1/inter-service
client = InterServiceClient(
    base_url="https://api.example.com",
    api_key="key",
    api_prefix="/v2/api"  # Custom prefix
)

# Override per request
response = client.request(
    endpoint="custom",
    api_prefix="/internal"
)
```

## API Reference

### InterServiceClient

```python
InterServiceClient(
    base_url: str,
    api_key: str,
    api_prefix: str = "/api/v1/inter-service",
    timeout: int = 30,
    retry_attempts: int = 3,
    ecc_private_key: str = None,
    ecc_public_key: str = None
)
```

#### Parameters

- `base_url` (str): Base URL of the API (e.g., "https://api.example.com")
- `api_key` (str): Bearer token for authentication
- `api_prefix` (str, optional): API prefix. Default: "/api/v1/inter-service"
- `timeout` (int, optional): Request timeout in seconds. Default: 30
- `retry_attempts` (int, optional): Number of retry attempts. Default: 3
- `ecc_private_key` (str, optional): ECC private key for decryption
- `ecc_public_key` (str, optional): ECC public key for encryption

### request()

```python
client.request(
    endpoint: str,
    path_params: dict = None,
    query_params: dict = None,
    method: str = "GET",
    data: dict = None,
    headers: dict = None,
    encrypt: bool = False,
    decrypt: bool = False,
    timeout: int = None,
    api_prefix: str = None
) -> dict
```

#### Parameters

- `endpoint` (str): Endpoint template (e.g., "users/{user_id}")
- `path_params` (dict, optional): Path parameters for substitution
- `query_params` (dict, optional): Query string parameters
- `method` (str, optional): HTTP method. Default: "GET"
- `data` (dict, optional): Request body (JSON)
- `headers` (dict, optional): Additional headers
- `encrypt` (bool, optional): Auto-encrypt request data. Default: False
- `decrypt` (bool, optional): Auto-decrypt response. Default: False
- `timeout` (int, optional): Override default timeout
- `api_prefix` (str, optional): Override default API prefix

#### Returns

```python
{
    "status": "success" | "error",
    "data": {...} | None,
    "status_code": int,
    "error": None | str
}
```

## Error Handling

```python
response = client.request(endpoint="users/123")

if response["status"] == "success":
    user = response["data"]
    print(user)
else:
    print(f"Error: {response['error']}")
    print(f"Status code: {response['status_code']}")
```

## Configuration

### Environment Variables

```bash
# Recommended approach
export API_BASE_URL="https://api.example.com"
export API_KEY="your-secret-key"
export ECC_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----..."
export ECC_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----..."
```

```python
import os
from inter_service_sdk import InterServiceClient

client = InterServiceClient(
    base_url=os.getenv("API_BASE_URL"),
    api_key=os.getenv("API_KEY"),
    ecc_private_key=os.getenv("ECC_PRIVATE_KEY"),
    ecc_public_key=os.getenv("ECC_PUBLIC_KEY")
)
```

## Development

### Install Development Dependencies

```bash
pip install -r requirements-dev.txt
```

### Run Tests

```bash
pytest tests/ -v
```

### Run Tests with Coverage

```bash
pytest tests/ --cov=inter_service_sdk --cov-report=html
```

### Code Formatting

```bash
black inter_service_sdk tests
```

### Type Checking

```bash
mypy inter_service_sdk
```

## Examples

See the `examples/` directory for more usage examples:

- `basic_usage.py` - Simple GET request
- `with_encryption.py` - ECC encryption example
- `search_example.py` - Query parameters example
- `post_example.py` - POST request example

## License

MIT License - see LICENSE file for details.

## Contributing

Contributions are welcome! Please open an issue or submit a pull request.

## Support

For questions or issues, please open a GitHub issue.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AlexanderRyzhko/inter-service-sdk",
    "name": "inter-service-sdk",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "http, client, server, api, rest, fastapi, inter-service, microservices, authentication, encryption, ecc, bearer-token",
    "author": "Blazel",
    "author_email": "Blazel <dev@blazel.com>",
    "download_url": "https://files.pythonhosted.org/packages/be/7a/c414339c484ec2a0d09644209b437aa7bf2ea21c2d7e2372a4da09e6e736/inter_service_sdk-1.0.2.tar.gz",
    "platform": null,
    "description": "# Inter-Service SDK\n\nGeneric HTTP client for secure service-to-service communication with bearer token authentication and optional ECC encryption.\n\n## Features\n\n- \ud83d\udd10 **Bearer Token Auth** - Automatic authentication headers\n- \ud83d\udd12 **Optional ECC Encryption** - End-to-end encryption for sensitive data\n- \ud83c\udfaf **Path & Query Parameters** - Clean parameter substitution\n- \ud83d\udd04 **Automatic Retries** - Exponential backoff for failed requests\n- \ud83d\udcdd **Structured Logging** - Request/response tracking\n- \ud83d\ude80 **Zero Dependencies** - Only requests and cryptography (optional)\n\n## Installation\n\n```bash\npip install inter-service-sdk\n```\n\n## Quick Start\n\n```python\nfrom inter_service_sdk import InterServiceClient\n\n# Initialize client\nclient = InterServiceClient(\n    base_url=\"https://api.example.com\",\n    api_key=\"your-secret-key\"\n)\n\n# Make a request\nresponse = client.request(\n    endpoint=\"users/{user_id}\",\n    path_params={\"user_id\": 123}\n)\n\nprint(response[\"data\"])\n```\n\n## Usage\n\n### Basic GET Request\n\n```python\nclient = InterServiceClient(\n    base_url=\"https://api.example.com\",\n    api_key=\"your-api-key\"\n)\n\n# GET /api/v1/inter-service/users/123\nuser = client.request(\n    endpoint=\"users/{user_id}\",\n    path_params={\"user_id\": 123}\n)\n```\n\n### With Query Parameters\n\n```python\n# GET /api/v1/inter-service/users/search?q=john&type=email&limit=10\nresults = client.request(\n    endpoint=\"users/search\",\n    query_params={\n        \"q\": \"john\",\n        \"type\": \"email\",\n        \"limit\": 10\n    }\n)\n```\n\n### POST Request\n\n```python\n# POST /api/v1/inter-service/users\nnew_user = client.request(\n    endpoint=\"users\",\n    method=\"POST\",\n    data={\n        \"name\": \"John Doe\",\n        \"email\": \"john@example.com\"\n    }\n)\n```\n\n### With ECC Encryption\n\n```python\nclient = InterServiceClient(\n    base_url=\"https://api.example.com\",\n    api_key=\"your-api-key\",\n    ecc_private_key=os.getenv(\"PRIVATE_KEY\"),\n    ecc_public_key=os.getenv(\"PUBLIC_KEY\")\n)\n\n# Auto-decrypt response\ncredentials = client.request(\n    endpoint=\"credentials/{id}\",\n    path_params={\"id\": 456},\n    decrypt=True\n)\n\n# Auto-encrypt request\nclient.request(\n    endpoint=\"secrets\",\n    method=\"POST\",\n    data={\"secret\": \"sensitive data\"},\n    encrypt=True\n)\n```\n\n### Custom API Prefix\n\n```python\n# Default prefix: /api/v1/inter-service\nclient = InterServiceClient(\n    base_url=\"https://api.example.com\",\n    api_key=\"key\",\n    api_prefix=\"/v2/api\"  # Custom prefix\n)\n\n# Override per request\nresponse = client.request(\n    endpoint=\"custom\",\n    api_prefix=\"/internal\"\n)\n```\n\n## API Reference\n\n### InterServiceClient\n\n```python\nInterServiceClient(\n    base_url: str,\n    api_key: str,\n    api_prefix: str = \"/api/v1/inter-service\",\n    timeout: int = 30,\n    retry_attempts: int = 3,\n    ecc_private_key: str = None,\n    ecc_public_key: str = None\n)\n```\n\n#### Parameters\n\n- `base_url` (str): Base URL of the API (e.g., \"https://api.example.com\")\n- `api_key` (str): Bearer token for authentication\n- `api_prefix` (str, optional): API prefix. Default: \"/api/v1/inter-service\"\n- `timeout` (int, optional): Request timeout in seconds. Default: 30\n- `retry_attempts` (int, optional): Number of retry attempts. Default: 3\n- `ecc_private_key` (str, optional): ECC private key for decryption\n- `ecc_public_key` (str, optional): ECC public key for encryption\n\n### request()\n\n```python\nclient.request(\n    endpoint: str,\n    path_params: dict = None,\n    query_params: dict = None,\n    method: str = \"GET\",\n    data: dict = None,\n    headers: dict = None,\n    encrypt: bool = False,\n    decrypt: bool = False,\n    timeout: int = None,\n    api_prefix: str = None\n) -> dict\n```\n\n#### Parameters\n\n- `endpoint` (str): Endpoint template (e.g., \"users/{user_id}\")\n- `path_params` (dict, optional): Path parameters for substitution\n- `query_params` (dict, optional): Query string parameters\n- `method` (str, optional): HTTP method. Default: \"GET\"\n- `data` (dict, optional): Request body (JSON)\n- `headers` (dict, optional): Additional headers\n- `encrypt` (bool, optional): Auto-encrypt request data. Default: False\n- `decrypt` (bool, optional): Auto-decrypt response. Default: False\n- `timeout` (int, optional): Override default timeout\n- `api_prefix` (str, optional): Override default API prefix\n\n#### Returns\n\n```python\n{\n    \"status\": \"success\" | \"error\",\n    \"data\": {...} | None,\n    \"status_code\": int,\n    \"error\": None | str\n}\n```\n\n## Error Handling\n\n```python\nresponse = client.request(endpoint=\"users/123\")\n\nif response[\"status\"] == \"success\":\n    user = response[\"data\"]\n    print(user)\nelse:\n    print(f\"Error: {response['error']}\")\n    print(f\"Status code: {response['status_code']}\")\n```\n\n## Configuration\n\n### Environment Variables\n\n```bash\n# Recommended approach\nexport API_BASE_URL=\"https://api.example.com\"\nexport API_KEY=\"your-secret-key\"\nexport ECC_PRIVATE_KEY=\"-----BEGIN PRIVATE KEY-----...\"\nexport ECC_PUBLIC_KEY=\"-----BEGIN PUBLIC KEY-----...\"\n```\n\n```python\nimport os\nfrom inter_service_sdk import InterServiceClient\n\nclient = InterServiceClient(\n    base_url=os.getenv(\"API_BASE_URL\"),\n    api_key=os.getenv(\"API_KEY\"),\n    ecc_private_key=os.getenv(\"ECC_PRIVATE_KEY\"),\n    ecc_public_key=os.getenv(\"ECC_PUBLIC_KEY\")\n)\n```\n\n## Development\n\n### Install Development Dependencies\n\n```bash\npip install -r requirements-dev.txt\n```\n\n### Run Tests\n\n```bash\npytest tests/ -v\n```\n\n### Run Tests with Coverage\n\n```bash\npytest tests/ --cov=inter_service_sdk --cov-report=html\n```\n\n### Code Formatting\n\n```bash\nblack inter_service_sdk tests\n```\n\n### Type Checking\n\n```bash\nmypy inter_service_sdk\n```\n\n## Examples\n\nSee the `examples/` directory for more usage examples:\n\n- `basic_usage.py` - Simple GET request\n- `with_encryption.py` - ECC encryption example\n- `search_example.py` - Query parameters example\n- `post_example.py` - POST request example\n\n## License\n\nMIT License - see LICENSE file for details.\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request.\n\n## Support\n\nFor questions or issues, please open a GitHub issue.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Complete framework for inter-service communication with client, server utilities, auth and encryption",
    "version": "1.0.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/AlexanderRyzhko/inter-service-sdk/issues",
        "Documentation": "https://github.com/AlexanderRyzhko/inter-service-sdk#readme",
        "Homepage": "https://github.com/AlexanderRyzhko/inter-service-sdk",
        "Source Code": "https://github.com/AlexanderRyzhko/inter-service-sdk"
    },
    "split_keywords": [
        "http",
        " client",
        " server",
        " api",
        " rest",
        " fastapi",
        " inter-service",
        " microservices",
        " authentication",
        " encryption",
        " ecc",
        " bearer-token"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a50ac3b4bccfd58a676f3b7a9691c2149a3163be14f5a700288fd5fb2dd0326f",
                "md5": "9d594ed862d8ccc20e10225c05cc786d",
                "sha256": "1c583d2aca88c836938e93a5fe6a33817e2762521e2f32177730945d14a49336"
            },
            "downloads": -1,
            "filename": "inter_service_sdk-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9d594ed862d8ccc20e10225c05cc786d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 12710,
            "upload_time": "2025-10-06T18:46:07",
            "upload_time_iso_8601": "2025-10-06T18:46:07.302348Z",
            "url": "https://files.pythonhosted.org/packages/a5/0a/c3b4bccfd58a676f3b7a9691c2149a3163be14f5a700288fd5fb2dd0326f/inter_service_sdk-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "be7ac414339c484ec2a0d09644209b437aa7bf2ea21c2d7e2372a4da09e6e736",
                "md5": "128dc0179003e0469f8c50be8b04f661",
                "sha256": "44d50512b353df9df8937ca7f0f43bcca1a52cffa63c014bd566237032aca0e8"
            },
            "downloads": -1,
            "filename": "inter_service_sdk-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "128dc0179003e0469f8c50be8b04f661",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 20346,
            "upload_time": "2025-10-06T18:46:08",
            "upload_time_iso_8601": "2025-10-06T18:46:08.710802Z",
            "url": "https://files.pythonhosted.org/packages/be/7a/c414339c484ec2a0d09644209b437aa7bf2ea21c2d7e2372a4da09e6e736/inter_service_sdk-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-06 18:46:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AlexanderRyzhko",
    "github_project": "inter-service-sdk",
    "github_not_found": true,
    "lcname": "inter-service-sdk"
}
        
Elapsed time: 0.89061s