Skip to main content

Python lightweight client library for Incognia APIs

Project description

Incognia API Python Client 🐍

Python 3.8+ test workflow

Installation

You can install the IncogniaAPI using the following command:

pip install incognia-python

Usage

Configuration

Before calling the API methods, you need to create an instance of the IncogniaAPI class.

from incognia.api import IncogniaAPI

api = IncogniaAPI('client-id', 'client-secret')

Incognia API

The implementation is based on the Incognia API Reference.

Authentication

Authentication is done transparently, so you don't need to worry about it.

Registering New Signup

This method registers a new signup for the given installation and a structured address, an address line or coordinates, returning a dict, containing the risk assessment and supporting evidence:

from incognia.api import IncogniaAPI
from incognia.models import StructuredAddress, Coordinates

api = IncogniaAPI('client-id', 'client-secret')

# with structured address, a dict:
structured_address: StructuredAddress = {
    'locale': 'en-US',
    'country_name': 'United States of America',
    'country_code': 'US',
    'state': 'NY',
    'city': 'New York City',
    'borough': 'Manhattan',
    'neighborhood': 'Midtown',
    'street': 'W 34th St.',
    'number': '20',
    'complements': 'Floor 2',
    'postal_code': '10001'
}
assessment: dict = api.register_new_signup('installation-id', structured_address=structured_address)

# with address line:
address_line: str = '350 Fifth Avenue, Manhattan, New York 10118'
assessment: dict = api.register_new_signup('installation-id', address_line=address_line)

# with coordinates, a dict:
coordinates: Coordinates = {
    'lat': 40.74836007062138,
    'lng': -73.98509720487937
}
assessment: dict = api.register_new_signup('installation-id', address_coordinates=coordinates)

# with external_id:
external_id: str = 'external-id'
assessment: dict = api.register_new_signup('installation-id', external_id=external_id)

# with policy_id:
policy_id: str = 'policy-id'
assessment: dict = api.register_new_signup('installation-id', policy_id=policy_id)

# with account_id:
account_id: str = 'account-id'
assessment: dict = api.register_new_signup('installation-id', account_id=account_id)

Registering Feedback

This method registers a feedback event for the given identifiers (optional arguments) related to a signup, login or payment.

import datetime as dt
from incognia.api import IncogniaAPI
from incognia.feedback_events import FeedbackEvents  # feedbacks are strings.

api = IncogniaAPI('client-id', 'client-secret')

api.register_feedback(FeedbackEvents.ACCOUNT_TAKEOVER,
                      occurred_at=dt.datetime(2024, 7, 22, 15, 20, 0, tzinfo=dt.timezone.utc),
                      installation_id='installation-id',
                      account_id='account-id')

Registering Payment

This method registers a new payment for the given installation and account, returning a dict, containing the risk assessment and supporting evidence.

from typing import List
from incognia.api import IncogniaAPI
from incognia.models import TransactionAddress, PaymentValue, PaymentMethod

api = IncogniaAPI('client-id', 'client-secret')

addresses: List[TransactionAddress] = [
    {
        'type': 'shipping',
        'structured_address': {
            'locale': 'pt-BR',
            'country_name': 'Brasil',
            'country_code': 'BR',
            'state': 'SP',
            'city': 'São Paulo',
            'borough': '',
            'neighborhood': 'Bela Vista',
            'street': 'Av. Paulista',
            'number': '1578',
            'complements': 'Andar 2',
            'postal_code': '01310-200'
        },
        'address_coordinates': {
            'lat': -23.561414,
            'lng': -46.6558819
        }
    }
]

payment_value: PaymentValue = {
    'amount': 5.0,
    'currency': 'BRL'
}

payment_methods: List[PaymentMethod] = [
    {
        'type': 'credit_card',
        'credit_card_info': {
            'bin': '123456',
            'last_four_digits': '1234',
            'expiry_year': '2027',
            'expiry_month': '10'
        }
    },
    {
        'type': 'debit_card',
        'debit_card_info': {
            'bin': '123456',
            'last_four_digits': '1234',
            'expiry_year': '2027',
            'expiry_month': '10'
        }
    }
]

policy_id: str = 'policy-id'

assessment: dict = api.register_payment('installation-id',
                                        'account-id',
                                        'external-id',
                                        addresses=addresses,
                                        payment_value=payment_value,
                                        payment_methods=payment_methods,
                                        policy_id=policy_id)

Registering Login

This method registers a new login for the given installation and account, returning a dict, containing the risk assessment and supporting evidence.

from incognia.api import IncogniaAPI

api = IncogniaAPI('client-id', 'client-secret')

policy_id: str = 'policy-id'

assessment: dict = api.register_login('installation-id', 
                                      'account-id', 
                                      'external-id', 
                                      policy_id='policy_id')

Error Handling

Every method call can throw IncogniaHTTPError and IncogniaError.

IncogniaHTTPError is thrown when the API returned an unexpected http status code.

IncogniaError represents unknown errors, like required parameters none or empty.

How to Contribute

Your contributions are highly appreciated. If you have found a bug or if you have a feature request, please report them at this repository issues section.

Development

Versioning

This project uses Semantic Versioning, where version follows v{MAJOR}.{MINOR}.{PATCH} format. In summary:

  • Major version update - Major functionality changes. Might not have direct backward compatibility. For example, multiple public API parameter changes.
  • Minor version update - Additional features. Major bug fixes. Might have some minor backward compatibility issues. For example, an extra parameter on a callback function.
  • Patch version update - Minor features. Bug fixes. Full backward compatibility. For example, extra fields added to the public structures with version bump.

Release

On GitHub, you should merge your changes to the main branch, create the git versioning tag and finally push those changes:

$ git checkout main
$ git pull
$ git merge <your_branch>
$ git tag -a v<version> -m "<description>"
$ git push origin HEAD --tags
  • example:
$ git checkout main
$ git pull
$ git merge feat/some-feature
$ git tag -a v2.1.0 -m "This release adds some feature..."
$ git push origin HEAD --tags

Our CI will build images with the tagged version and publish them to our PyPI repository.

What is Incognia?

Incognia is a location identity platform for mobile apps that enables:

  • Real-time address verification for onboarding
  • Frictionless authentication
  • Real-time transaction verification

License

License: MIT

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

incognia_python-2.1.1.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

incognia_python-2.1.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file incognia_python-2.1.1.tar.gz.

File metadata

  • Download URL: incognia_python-2.1.1.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for incognia_python-2.1.1.tar.gz
Algorithm Hash digest
SHA256 d4bb60a71c27a3becf93d0f6e34e060437a42a75f409c930ffc6e08d545ad461
MD5 01acaf38122e78e7d1948930a8edbfc5
BLAKE2b-256 405c3b533fae196fd78c716c12515dc5c0e4f571626c6a0867cb34db5bf4dc16

See more details on using hashes here.

File details

Details for the file incognia_python-2.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for incognia_python-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 532a17c11126fb18bb820c9efedc92ab8be070bfd7f0b01a708c664cf33e96ee
MD5 33598206a65ce2256919c4fc10e8c683
BLAKE2b-256 91541cb52af2e5bbb0ee8f8bd56db3b605db8924025fd419d15cffe7dccea376

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