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.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: ma_kyc_ri_pfpy-0.1.1.tar.gz
  • Upload date:
  • Size: 9.1 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.1.tar.gz
Algorithm Hash digest
SHA256 12d88784dd13569da1740008118e52b8dbe6ee1ea28bb98399ce3c3937c5b723
MD5 be09149657a934a164cb6b4924e4ed5c
BLAKE2b-256 adfbd18f8619798ad46848e7bf09d2f44fe398e4e826828378891318ed51633d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ma_kyc_ri_pfpy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 71409c6c6f78bcfacdb3bb987066698863a8a980e24fd6b3ab5de1db6bc04015
MD5 284a377df36159fa4a7e54e3b64a3eef
BLAKE2b-256 bcac4c3390c0f0d747d7af24b8bbbac2f8dfa043a2676bb88f1de4465d7fdc7f

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