Skip to main content

A collection of Python connection clients for E360 Microservices

Project description

E360 Clients Core

pipeline status

Installation

Use the E360 Artifactory package manager e360-pypi-local to install clients_core.

Requires Python 3.12 or newer.

pip install clients_core --index-url=https://rwes-artifactory01.internal.imsglobal.com/artifactory/api/pypi/e360-pypi-local/simple

Usage with Service Directory

  1. Create a TokenHandler, with the right configuration for identity.
from clients_core.authentication.token_handler import OIDCTokenHandler

token_handler = OIDCTokenHandler("<oidc_token_endpoint>", "<oidc_client_id>", "<oidc_client_secret>")
  1. Create a SecureRestClient for ServiceDirectory, and pass the token handler
from clients_core.secured_rest_client import SecuredRestClient
rest_client = SecuredRestClient("<url-to-service-directory", ["service-dir-scopes"], token_handler)
  1. Create a ServiceDirectoryClient using the rest client
from sd_clients.service_directory_client import ServiceDirectoryClient
sd_client = ServiceDirectoryClient(rest_client)
  1. The SD client can now be passed to ApiMatchClient which will allow lookups of services
from clients_core.api_match_client import ApiMatchClient, MatchSpec

match_client = ApiMatchClient(sd_client)
match_spec = MatchSpec("service-name", "endpoint-name",1 ,0, 1, ["service-scopes"])
service_rest_client = match_client.get_secured_client(match_spec, token_handler)

The service rest client can now be passed to a microservice client, or used directly to make REST calls to the target service

Usage with cache

If it is desired to use a cache, we need to wrap our TokenHandler with TokenCache. There are currently two Cache implementations, RedisCache and DictCache. RedisCache requires a connection URL when instantiated:

from clients_core.authentication.cache import RedisCache
from clients_core.authentication.token_cache import TokenCache

cache = RedisCache("<redis-connection-url>")
token_cache = TokenCache(cache, token_handler)  # token handler as created in step .1

token_cache can now be used in place of token_handler.

Development and Testing

Install uv (Python 3.12+ recommended).

uv sync --group dev

Run checks and tests:

uv run ruff check clients_core tests
uv run ruff format --check clients_core tests
uv run pytest

Run a single test file or test:

uv run pytest tests/test_secured_rest_client.py
uv run pytest tests/test_secured_rest_client.py::test_simple_post

Optional type check:

uv run mypy clients_core

Build a wheel locally:

uv build --out-dir dist

On the corporate network, you can point resolution at Artifactory, for example:

export UV_INDEX_URL=https://rwes-artifactory01.internal.imsglobal.com/artifactory/api/pypi/e360-pypi-local/simple
uv sync --group dev

See pyproject.toml for optional explicit e360-pypi indexes when adding internal-only dependencies.

Deployments

Auto CI enabled.

A deployment will happen every time a merge request is merged into master AND the version number is incremented in the clients_core/__init__.py file.

Development

After cloning this repository:

uv sync --group dev

Install pre-commit hooks:

uv run pre-commit install --install-hooks --overwrite

UML

Project details


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 Distribution

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

clients_core-4.0.2-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file clients_core-4.0.2-py3-none-any.whl.

File metadata

  • Download URL: clients_core-4.0.2-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for clients_core-4.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 15ca5511e1eb5a0004f0291d548dfa2e6f94a6f6d21662cbb48eb836c1037d49
MD5 0dbff24c9b3430b559afc0883499ed3d
BLAKE2b-256 7c18cf387b6a1ac05404fc16bf2965590f92d170c1907f882490d46720a3c77d

See more details on using hashes here.

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