SugarCRM
Python client for SugarCRM API.
Example Usage
import sugarcrm
# Connect
url = "http://your-sugarcrm-domain/service/v4/rest.php"
session = sugarcrm.Session(url, username, password)
# Create a new note
note = sugarcrm.Note(name="Test Note")
# Save note
session.set_entry(note)
# Add attachment to note
session.set_note_attachment(note, "sugarcrm.py")
# Query for all notes that have a name that begins with "Test"
note_query = sugarcrm.Note(name="Test%")
results = session.get_entry_list(note_query)
# Query for all contacts with the first name "Mylee"
contact_query = sugarcrm.Contact(first_name="Mylee")
results = session.get_entry_list(contact_query)
# Get the email address for the user assigned to an Opportunity
op = session.get_entry("Opportunities", "82f72939-735e-53a2-0944-5418c4edae2a")
user = session.get_entry("Users", op.assigned_user_id)
print user.email1
# Change the status of an Opportunity
op = sugarcrm.Opportunity(id="82f72939-735e-53a2-0944-5418c4edae2a")
op.sales_stage = "Approved"
session.set_entry(op)
# Extract all non-empty email fields from all Contacts in SugarCRM
emails = set()
contact_query = sugarcrm.Contact() # No filters provider finds all objects
contact_count = session.get_entries_count(contact_query, deleted=True)
print "Extracting emails from %d Contacts" % contact_count
# Grab 100 Contact objects at a time from SugarCRM
for offset in range(0, count, 100):
contacts = session.get_entry_list(contact_query, deleted=True,
max_results=100, offset=offset)
for contact in contacts:
for field in dir(contact):
if field.find("email") >= 0 and getattr(contact, field, "").find("@") >= 0:
emails.add(getattr(contact, field).lower())
print "Found %d emails" % len(emails)
Install
The latest stable version can always be installed or updated via pip:
$ pip install sugarcrm
If the above fails, please use easy_install instead:
$ easy_install sugarcrm
Session Object
- class sugarcrm.Session(url, username, password, app=”Python”, lang=”en_us”, verify=True)
The main class used to connect to the SugarCRM API and make requests with.
url = "http://your-sugarcrm-domain/service/v4/rest.php"
session = sugarcrm.Session(url, username, password)
The verify parameter is passed directly to the python-requests library that is used to make HTTP POST requests to the SugarCRM API. Read more about this parameter from the python-requests documentation: http://docs.python-requests.org/en/latest/user/advanced/#ssl-cert-verification
Available Methods
- get_available_modules(filter=”default”)
Retrieves a list of available modules in the system. Possible filter values: “default”, “mobile”, “all”
modules = session.get_available_modules()
for m in modules:
print m.module_key
- get_entry(module, object_id, links={}, track_view=False)
Retrieves a single object based on object ID.
note = session.get_entry("Notes", "f0c78aab-e051-174a-12aa-5439a7146977")
print note.name
# Get a lead and specific fields from linked contacts in one query
links = {'Contacts': ['id', 'first_name', 'last_name']}
lead = session.get_entry("Leads", "d7dac88d-ce33-d98a-da8b-5418bba9e664",
links=links)
for c in lead.contacts:
print c.id, c.first_name, c.last_name
- get_entries(module, object_ids, track_view=False)
Retrieves a list of objects based on specified object IDs.
ids = [
"f0c78aab-e051-174a-12aa-5439a7146977",
"32f02fj2-4ggn-4nnf-fs33-f3fh3f93n333",
"82f72939-735e-53a2-0944-5418c4edae2a",
]
notes = session.get_entries("Notes", ids)
for note in notes:
print note.name
- get_entries_count(query_object, deleted=False)
Retrieves a count of beans based on query specifications.
# Get a count of all Contacts with a first name of "Fred"
# and include Contacts that have been deleted
contact_query = sugarcrm.Contact(first_name="Fred")
contacts = session.get_entries_count(contact_query, deleted=True)
for contact in contacts:
print contact.first_name, contact.last_name
- get_entry_list(query_object, fields=[], links={}, order_by=””, max_results=0, offset=0, deleted=False, favorites=False)
Retrieves a list of objects based on query specifications.
# Get a list of all Notes with a name that begins with "Test"
note_query = sugarcrm.Note(name="Test%")
notes = session.get_entry_list(note_query)
for note in notes:
print note.name
# Get a list of all Opportunities created since Sept 1, 2014 and include
# data about link contacts with each Opportunitity returned
q = sugarcrm.Opportunity()
q.query = "opportunities.date_entered > '2014-09-01'"
links = {'Contacts': ['id', 'first_name', 'last_name']}
results = session.get_entry_list(q, links=links)
for o in results:
for c in o.contacts:
print o.id, c.id, c.first_name, c.last_name
- login(username, password, app=”Python”, lang=”en_us”)
Logs a user into the SugarCRM application.
- set_document_revision(document, file)
Creates a new document revision for a specific document record.
doc = sugarcrm.Document(document_name="Test Doc", revision=1)
session.set_entry(doc)
session.set_document_revision(doc, "/path/to/test.pdf")
- set_entry(sugar_object)
Creates or updates a specific object.
note = sugarcrm.Note()
note.name = "Test Note"
note.assigned_user_id = "82f72939-735e-53a2-0944-5418c4edae2a"
session.set_entry(note)
print note.id
- set_note_attachment(note, attachment)
Creates an attachmentand associates it to a specific note object.
with open("test1.pdf") as pdf_file:
session.set_note_attachment(note1, pdf_file)
session.set_note_attachment(note2, "test2.pdf")
print note1.filename, note2.filename
- set_relationship(parent, child, delete=False)
Sets the relationships between two records.
doc = sugarcrm.Document(document_name="Test Doc", revision=1)
session.set_entry(doc)
session.set_document_revision(doc, "/path/to/test.pdf")
opportunity = session.get_entry("Opportunities", "5b671886-cfe4-36f5-fa9d-5418a24e4aca")
session.set_relationship(opportunity, doc)
SugarCRM Objects
>>> call = sugarcrm.Call()
>>> print call.module
"Calls"
>>> campaign = sugarcrm.Campaign()
>>> print campaign.module
"Campaigns"
>>> contact = sugarcrm.Contact()
>>> print contact.module
"Contacts"
>>> document = sugarcrm.Document()
>>> print document.module
"Documents"
>>> email = sugarcrm.Email()
>>> print email.module
"Emails"
>>> lead = sugarcrm.Lead()
>>> print lead.module
"Leads"
>>> module = sugarcrm.Module()
>>> print module.module
"Modules"
>>> note = sugarcrm.Note()
>>> print note.module
"Notes"
>>> opportunity = sugarcrm.Opportunity()
>>> print opportunity.module
"Opportunities"
>>> product = sugarcrm.Product()
>>> print product.module
"Products"
>>> prospect = sugarcrm.Prospect()
>>> print prospect.module
"Prospects"
>>> prospect_list = sugarcrm.ProspectList()
>>> print prospect_list.module
"ProspectLists"
>>> quote = sugarcrm.Quote()
>>> print quote.module
"Quotes"
>>> report = sugarcrm.Report()
>>> print report.module
"Reports"
>>> user = sugarcrm.User()
>>> print user.module
"Users"
Development Version
The latest development version can be installed directly from GitHub:
$ pip install --upgrade https://github.com/ryanss/sugarcrm/tarball/master
Contributions
Issues and Pull Requests are always welcome.
License
Code and documentation are available according to the MIT License (see LICENSE).
Metadata
Release files for sugarcrm 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sugarcrm-0.1.2.tar.gz | 9.3 kB | Without provenance | Details for sugarcrm-0.1.2.tar.gz |
Release files / sugarcrm-0.1.2.tar.gz
| Download URL | sugarcrm-0.1.2.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
df9912f54b000757e37795e65b8bfeb01161fc5647b35b3dbfd93e9e0a52a1c8
|
|
BLAKE2b-256 checksum How to use checksums |
925320f528f0bf4604c36ff05ba1142acc3d6007fdafc19c9b7c218732702281
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for sugarcrm 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.