Skip to main content

Talk to On-Prem Dynamics CRM

Project description


Client and Query Builder for On-Premise Microsoft Dynamics CRM.

Getting an Auth Token

The first task would be to fetch an authentication token. To do this pass your username and password to the token.get() function along with the URL of your CRM instance.

from pydynamics import token
tok = token.get('', 'DOMAIN\\username', 'password')

The returned token can then be used in subsequent client calls.

Create a client instance

Pass the token generated above to the Client constructor along with the API URL.

from pydynamics.client import Client
client = Client(tok, '')

Building Queries

The package includes a query builder.

Select a single item

The below example returns a single contact record, selected on its GUID and selects 3 specific fields to return. the select() part is optional, a default field set will be returned if it is omitted.

from pydynamics.querybuilder import QueryBuilder
q = QueryBuilder('contacts').guid('1bf1c4cf-1ed1-e311-941c-0050568a018c').\
    select(['firstname','lastname', 'emailaddress1'])
result =

Select based on filters

The below example returns the first 2, based on the limit(), contacts that contain the string "flowplex" within the emailaddress1 field and implements ordering and return field selection.

from pydynamics.querybuilder import QueryBuilder
q = QueryBuilder('contacts').\
    filter('emailaddress1', 'contains', 'flowplex', 'str').\
    select(['firstname','lastname', 'emailaddress1']).\
    order(['lastname'],'asc').limit(0 ,2)
result =

Create a record

The below creates a contact entity with the data provided to the query builder. The GUID of the new item will be returned if successful.

from pydynamics.querybuilder import QueryBuilder
q = QueryBuilder('contacts').data({
    'firstname': 'Dan',
    'lastname': 'Test',
    'emailaddress1': ''
guid = client.create(q)

Update a record

The below updates the firstname field on the specific contact record.

from pydynamics.querybuilder import QueryBuilder
q = QueryBuilder('contacts').guid('1bf1c4cf-1ed1-e311-941c-0050568a018c').\
    data({'firstname': 'Daniel'})

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 pydynamics, version 0.0.9
Filename, size File type Python version Upload date Hashes
Filename, size pydynamics-0.0.9.tar.gz (5.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page