Skip to main content

A library providing utils for PassFort 3rd party integrations.

Project description

ma-kyc-ri-pfpy

This is the pfpy (pronounced "puff py") package, a python package for integrating with PassFort. The goal of this package is to provide common utils, such as signature validation that allow web applications to integrate easily with PassFort.

Installation

If you want to use this package in your project, just install it using pip:

An example using uv (Python package installer and resolver, written in Rust). More info on uv can be found here: (https://github.com/astral-sh/uv)[https://github.com/astral-sh/uv]:

  • uv pip install git+https://github.com/moodysanalytics/ma-kyc-ri-pf-pfpy.git@main#egg=pfpy

The package will be pulle directly from the github repo that sits inside the Moody's Github org.

Usage

You need to have set a PASSFORT_INTEGRATION_SECRET_KEY environment variable, which is used to sign requests.

After that is set, simply import the relevant classes from pfpy.auth and use them in your request handlers.

NOTE: At the moment only FastApi has been tested in deployment with the validation classes (but theoretically any framework should work).

pfpy uses Pydantic to validate different kinds of data. If the data is not valid, an exception will be thrown that should be handled by the application.

An example with FastApi is below:

from pfpy.auth.parsed_header import ParsedSignedHeaderRequest
from pfpy.auth.parsed_url import ParsedSignedUrl
from pfpy.types.response_types import PassFortEntityDataCheck


@router.post("/checks")
async def checks(
    request: Request, request_body: PassfortIntegrationEntityDataCheckRequest
) -> PassFortEntityDataCheck | dict[str, Any]:

    try:
        # If parsing fails, then we know the signature in the header was invalid
        ParsedSignedHeaderRequest(
            method=request.method,
            request_url=str(request.url),
            request_method=request.method,
            headers=dict(request.headers),
        )

        if request_body.demo_result:
            return PassfortIntegrationService.run_demo_check(request_body.demo_result).model_dump(
                exclude_none=True, mode="json"
            )

        return PassfortIntegrationService.entity_check(request_body)

    except Exception as e:
        raise HTTPException(status_code=404, detail=f"Signature header validation failed: {e}.")

@router.get("/external-resources/{bvd_id}/")
async def external_resources(
    request: Request,
    bvd_id: str,
    version: str,
    valid_until: str,
    auditee_id: str,
    signature: str,
    custom_data: Optional[str] = None,
):
    try:
        # If parsing fails, then we know the signature in the url was invalid
        ParsedSignedUrl(
            request_url=str(request.url),
            version=version,
            valid_until=valid_until,
            auditee_id=auditee_id,
            signature=signature,
            custom_data=custom_data,
        )

    except Exception as e:
        raise HTTPException(status_code=404, detail=f"URL signature validation failed.: {e}")

Contributing

  • If you wish to contribute to the package, the easiest way would be to install it as an editable local package, then pull it in as a local dependency.

  • This way you can edit the code and just run the local install command below to see the latest changes in whatever app you are using pfpy as a dependency:

  • git clone the repo

  • uv pip install -e /Users/path-to-the-package/ma-kyc-ri-pf-pfpy

Replace the path with the actual place where you cloned the repo.

Now, every time you change/add a bit of code, you can simply run the local install to reflect those changes.

How can I quickly set up my working environment?

  • The repo contains a Makefile. Simply running make will create a .venv and pull in all the dependencies of pfpy.

Some other commands you may find useful as you are developing for pfpy:

  • make test: This will run the unit test suite
  • make lint: This will run the flake8 linter
  • make format: This will format the repo using black
  • make pyright: This will type check everything using Pyright
  • make requirements: This will emit the requirements.txt file

Roadmap

  • Add extensive unit tests (in progress)
  • Test integration with Flask framework
  • Explore addition of decorators to the package
  • Explore definition of interfaces through abstract classes

Project details


Download files

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

Source Distribution

ma_kyc_ri_pfpy-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

ma_kyc_ri_pfpy-0.1.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file ma_kyc_ri_pfpy-0.1.0.tar.gz.

File metadata

  • Download URL: ma_kyc_ri_pfpy-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for ma_kyc_ri_pfpy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cdad4d18348277fd2ff7489752edde37e744ad8dba04635d6b8f404671b15edf
MD5 48239f17f54ad46560f96006cc71fdf2
BLAKE2b-256 4cfcc8fa9c57f9d7e2baad7bfcd34b669bcb79323e9a368c3c17d994aef5e211

See more details on using hashes here.

File details

Details for the file ma_kyc_ri_pfpy-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ma_kyc_ri_pfpy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f3de84fe1ec26b2fcae3771323dc313647931d8b1a46b029bb2fcba7ea371df4
MD5 e2fe1c3715e4fdb6d6559a4c1f9609e7
BLAKE2b-256 33645f5706ce8d054746f17a1c00e6fe2266f5dbb818f6401e5785eaa465f2cb

See more details on using hashes here.

Supported by

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