Skip to main content

A Python Wrapper for Leadfeeder's API

Project description

Build Status Contributors MIT License LinkedIn

Table of Contents

About The Project

Leadfeeder helps you discover companies that visited your website, by identifying visitors and tracking their behaviour. This Python package allows you to easily connect to Leadfeeder's API and build applications on top of it.

Getting Started

Prerequisites

This package only supports Python 3.

Installation

  1. Log in to your Leadfeeder account and get a free API Token
  2. Install the package
pip3 install leadfeeder

Usage

Import the package...

from leadfeeder import Leadfeeder

... then create an instance of Leadfeeder using your API Token.

API_TOKEN = '31kFml4zvl3cWDKoJwBplLoNRcc1PVRQP443sUnT'
leadfeeder = Leadfeeder(API_TOKEN)

Accounts

Get accounts associated with token

from pprint import pprint

accounts = leadfeeder.accounts()
pprint(accounts)

Assuming a valid token, you should expect an output similar to:

[{'attributes': {'name': 'www.somedomain.com',
                 'on_trial': False,
                 'subscription': 'lite',
                 'subscription_addons': [],
                 'timezone': 'America/New_York'},
  'id': '63229',
  'type': 'accounts'},
 {'attributes': {'name': 'www.otherdomain.com',
                 'on_trial': True,
                 'subscription': 'premium',
                 'subscription_addons': ['google_data_studio'],
                 'timezone': 'America/New_York'},
  'id': '66884',
  'type': 'accounts'}]

Get specific account

account = leadfeeder.account(account_id=accounts[0]['id'])

Custom Feeds

Get custom feeds associated with account

custom_feeds = leadfeeder.custom_feeds(account_id=account['id'])

Get specific custom feed associated with account

custom_feed = leadfeeder.custom_feed(account_id=account['id'],
                                     custom_feed_id=custom_feeds[0]['id'])

Leads

Get leads associated with account

from datetime import datetime

leads = leadfeeder.leads(account_id=account['id'],
                         start_date=datetime(2019, 6, 11),
                         end_date=datetime(2019, 6, 11),
                         page_number=1,
                         page_size=10)

Both page_number and page_size are optional arguments, used to control the response's pagination. They default to 1 and 10, respectively.

Get specific leads associated with account

lead = leadfeeder.lead(account_id=account['id'],
                       lead_id=custom_feed['id'])

Visits

Get visits of lead

lead_visits = leadfeeder.lead_visits(account_id=account['id'],
                                     lead_id=lead['id'],
                                     start_date=datetime(2019, 6, 11),
                                     end_date=datetime(2019, 6, 12),
                                     page_number=1,
                                     page_size=10)

Get visits of account

visits = leadfeeder.visits(account_id=account['id'],
                           start_date=datetime(2019, 6, 11),
                           end_date=datetime(2019, 6, 11),
                           page_number=1,
                           page_size=10)

Get visits of leads in a given custom feed

custom_feed_visits = leadfeeder.custom_feed_visits(account_id=account['id'],
                                                   custom_feed_id=custom_feed['id'],
                                                   start_date=datetime(2019, 6, 11),
                                                   end_date=datetime(2019, 6, 11),
                                                   page_number=1,
                                                   page_size=10)

Exports

To export leads in a custom feed, first request the export, then continuously check the status of the export until it is successfully processed.

Request an export

custom_feed_export_request = leadfeeder.custom_feed_export_request(account_id=account['id'],
                                                                   custom_feed_id=custom_feed['id'],
                                                                   start_date=datetime(2019, 6, 11),
                                                                   end_date=datetime(2019, 6, 11))

Get export status

custom_feed_export_status = leadfeeder.custom_feed_export_status(export_id=custom_feed_export_request['id'])

If the export is successfully processed, you should expect a response such as:

{'attributes': {'created_at': '2019-06-12T10:10:54.186+00:00',
                'download_url': 'https://api.leadfeeder.com/download/5c0f0a74-9acc-4094-a638-a639b253b14c.json',
                'status': 'processed',
                'status_url': 'https://api.leadfeeder.com/export-requests/5d05590e-8cfa-11e9-b8cc-6576fb85189c'},
 'id': '5d05590e-8cfa-11e9-b8cc-6576fb85189c',
 'type': 'export_requests'}

You can then proceed to download the JSON available at custom_feed_export_status['attributes']['download_url'].

For additional information, please access the API's official documentation.

Contributing

Any contributions are greatly appreciated.

  1. Clone the repository
  2. Create a new feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature)
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Testing

Make sure the requirements are satisfied then run py.test in the project's root.

License

Distributed under the MIT License. See LICENSE for more information.

Contact

LinkedIn

Project details


Download files

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

Files for leadfeeder, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size leadfeeder-0.0.2-py3-none-any.whl (6.7 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size leadfeeder-0.0.2.tar.gz (4.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page