Skip to main content
https://badge.fury.io/py/django-basecrm.svg https://travis-ci.org/yunojuno/django-basecrm.svg?branch=master

Django Basecrm

A Django app that connects to the BaseCRM API (v2)

This package is now Python3 only, and supports Django 1.11 and above. For previous versions please refer to the Python2 branch.

A lightweight Django app to wrap the requests library and provide easy endpoints for the BaseCRM API.

Note that this is not a complete client SDK; it’s a helper app that has the functionality we needed. Contributions gratefully accepted.

The utils module provides a request() method that allows less config-heavy calls to the BaseCRM API, relying on settings while still allowing all options to be passed and/or overridden, both for requests and for the API endpoint itself. There are also helpers to parse() and count() the results (parse strips the metadata, while count returns the server-side count pre pagination).

The helpers module also provides some higher level methods for interacting with the contacts, deals, pipeline and stages endpoints (and the top level __init__ module exposes these). There’s also a setting for retrieving and caching the stages for a pipeline (only 1 supported currently).

Features

  • Low configuration overhead, so it’s easy to call API methods from anywhere in your code

  • Pre-submission validation for CREATE and UPDATE calls will raise catchable custom exceptions

  • Flexible serializers make creating BaseCRM objects from Django ORM objects trivial

Current Limitations

  • Only a single pipeline is currently supported.

  • Stages and pipelines are, by default, cached at the app level (in memory), with no cachebusting method exposed.

  • No DELETE calls are implemented

  • CREATE and UPDATE are only implemented on contacts and deals endpoints

  • GET is only implemented for contacts, deals, notes, pipelines and stages

  • Serializers are only used one-way; they do not deserialize

  • Probably many others…

Installation

You can install Django-BaseCRM from PyPI with…:

pip install --upgrade django-basecrm

Setup

At a minimum, you will need to add the following to your settings.py:

BASECRM_API_URL='https://api.getbase.com/v2/'
BASECRM_API_KEY=xxxx
BASECRM_INSTANTIATE_ON_START=False # If this is set to True, the pipeline ID and stage IDs will be retrieved when the app is started for the first time, and then held in memory

…putting your own API key instead of xxx, obv. Note that the API url is fully qualified, including the protocol and trailing slash.

You’ll also need to add this app to your INSTALLED_APPS; it doesn’t really matter where (in terms of ordering)::

INSTALLED_APPS = [
    ...
    'django_basecrm',
    ...
]

Next, you’ll probably want to extend the serializers to cater for your models.

For example, let’s imagine you have an app called people that contains a your custom User profile model called Person, that represents the contacts you want to track in Base.

Let’s also imagine that your model has an attribute for info, a @property for phone and a OneToOne relationship with User.

Create people/serializers.py and paste the following code:

from django_basecrm import get_contacts, create_contact
from django_basecrm.serializers import ContactModelSerializer

class PersonSerializer(ContactModelSerializer):
    is_organization = False
    description = 'info'

    def get_email(self, obj):
        return obj.user.email

    class Meta:
        model = 'people.Person'

Things to note:

  • We’re extending ContactModelSerializer; there’s also a DealModelSerializer that behaves identically but is set for the deal endpoint’s fields

  • We set the is_organization field to False explicitly; assuming your model doesn’t have a field (or property) with the same name, this will never be automatically overridden.

  • The description field is set to get the value of your object’s info field at runtime

  • The phone field will similarly get the value of your object’s phone property at runtime; we don’t need to specify it as the fields are identically named

  • The email field, although not explicitly defined, will be populated by the return value of the get_email method. Any get_* method will always take priority in setting the serializer value for the related field.

  • The Meta.model attribute is set to a string, contianing both the app_name and the model_name – any other string format will fail. It is however possible to specify a class directly (e.g. model = Person).

  • Note that you can also specify fields as an attribute to the Meta subclass; this will override the serializer’s list of fields

Once you’ve got this far, you really only need to call the functions, perhaps creating a module within your people app to offer create_person_from_object methods and the like.

An example get_or_create function for a BaseCRM contact, using the above models and serializers, might look like::

def get_or_create_person(person_id):
    person = Person.objects.get(pk=person_id)
    base_contacts = django_basecrm.get_contacts(email=person.user.email))
    if len(base_contacts) > 1:
        # This shouldn't happen if we enforce email uniqueness in Django
        raise Exception()
    elif len(base_contacts) == 1:
        base_contact = base_contacts[0]
    else:
        serialized_person = PersonSerializer(person) # This is the serializer we defined above
        base_contact = django_basecrm.create_contact(serialized_person.to_dict())
    return base_contact

Contribute

Contributions are very welcome. Please fork and submit pull requests, with all code covered by unit tests as per the existing code.

Metadata

Release files for django-basecrm 0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-basecrm 0.7
File Size Uploaded
django-basecrm-0.7.tar.gz 20.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-basecrm 0.7
File Interpreter ABI Platform
django_basecrm-0.7-py3-none-any.whl Python 3 none any Details

Total release size: 40.8 kB

Release files / django-basecrm-0.7.tar.gz

Download URL django-basecrm-0.7.tar.gz
Size 20.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fdaeb40e6000112726afe5f096531c45d71bbd4531719d1260324b1a3dc2d3ad
BLAKE2b-256 checksum
How to use checksums
c0f1a55327698758433e8a2e68e9e8178d8b5dff0fa0acf317820a2d2ea9bcb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Release files / django_basecrm-0.7-py3-none-any.whl

Download URL django_basecrm-0.7-py3-none-any.whl
Size 20.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6e5517e98e087817b6dca4e01ef05d650d08e921ac0a2488ac3c55dd47d71f8
BLAKE2b-256 checksum
How to use checksums
8b4e769250672f681aa44abc305b65741003cb3a03e3eb5c8f4d10d70fd52b39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

Release history Release notifications | RSS feed

This release

0.7 This release

2 release files

0.6

2 release files

0.5

2 release files

0.4.0

2 release files

0.3.4

3 release files

0.3.3

3 release files

0.3.2

1 release file

0.3.1

1 release file

0.3

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2

2 release files

0.1

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page