Skip to main content

Python wrapper on Nutshell CRM JSON RPC API

Project description

Nutshell API

This is a work-in-progress attempt at a pythonic API for querying the Nutshell CRM API. It does not yet support modifying data in a Nutshell instance.

Installation

pip install nutshell

Usage

This package includes four primary modules

  • methods: provides Pydantic models for a selection of Nutshell API methods
    • model naming aligns with the API method names
  • responses: Pydantic models for the responses returned by the API
    • response models are names with the API method name followed by "Result" (e.g. FindActivityTypesResult)
  • entities: enums and Pydantic models to facilitate method creation and parsing results
  • NutshellAPI class: provides a means to batch query the API with multiple methods via asyncio
    • Must be instantiated with your Nutshell username and API key.

General flow

  • Instantiate API method calls and collect them in an iterable
  • Instantiate NutshellAPI with your Nutshell credentials
  • Pass the method calls iterable to the NutshellAPI instance
  • Call the API
  • Unpack the results
import asyncio
import os

from rich import print
import nutshell as ns

single_call = ns.FindActivityTypes()

nut = ns.NutshellAPI(os.getenv("NUTSHELL_USERNAME"), password=os.getenv("NUTSHELL_KEY"))
nut.api_calls = [single_call]
call_response = asyncio.run(nut.call_api())

for call in call_response:
    print(call)

Results are returned as a list of tuples. The first element is the method instance, the second is the response.

(
    FindActivityTypes(
        api_method='findActivityTypes',
        order_by='name',
        order_direction='ASC',
        limit=50,
        page=1,
        params={'orderBy': 'name', 'orderDirection': 'ASC', 'limit': 50, 'page': 1}
    ),
    FindActivityTypesResult(
        result=[
            ActivityTypes(stub=True, id=1, rev='1', entity_type='Activity_Types', name='Phone Call / Meeting'),
            ActivityTypes(stub=True, id=3, rev='3', entity_type='Activity_Types', name='Email/Log'),
        ]
    )
)

All responses have a result attribute that contains the data returned by the API. The data is returned as Pydantic models based on the API method invoked.

TODO

  • Handle errors returned from API
  • Convenience methods for common queries (Users, Leads, etc.)

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

nutshell-0.3.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

nutshell-0.3.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file nutshell-0.3.0.tar.gz.

File metadata

  • Download URL: nutshell-0.3.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Darwin/23.4.0

File hashes

Hashes for nutshell-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a4ad958fc6989cb747ccc009dcf8aa02d589add9a8fe4cd8d085172d7ab4710b
MD5 5fa852a364301e835ff2476c6187ef0c
BLAKE2b-256 72e8659c8604465cf0d519ebb6d38fd26b9d288892267fb57d38f90486aca2d7

See more details on using hashes here.

File details

Details for the file nutshell-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: nutshell-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Darwin/23.4.0

File hashes

Hashes for nutshell-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94e3afae6cb5c9d168438e0a64a771f11f7d65b0ec3713311abc43478f306ca2
MD5 1042fea78ccc13cb27e7f03133e8723a
BLAKE2b-256 330985f84a52b1feab9197dc5b599ffb0f7f8f88860ac596cfc2381bcb50407b

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