Skip to main content

CiviCRM v3/v4 REST API Python wrapper

Project description

Getting Started

This is a brand-new project and code is subject to change at any time.

Install with python3 -m pip install civipy. If you are using a Python version older than 3.11 and want to use pyproject.toml configuration, install with python3 -m pip install civipy[pyproject].

Configuration

Configure your credentials in environment variables, a .civipy file, or in pyproject.toml in a tools.civipy section. By default, CiviPy will read a .civipy file anywhere in the current working directory up to your project root, or your project's pyproject.toml file, or a .civipy file in the user's home folder. Settings in environment variables will overwrite any file settings. Alternatively, you can call civipy.config.SETTINGS.init() to set the configuration values.

Setting Environment Variable .civipy File pyproject.toml File
[tool.civipy]
Connection (required) CIVI_REST_BASE rest_base=http://civi.py rest-base = "http://civi.py"
API Version CIVI_API_VERSION api_version=4 api-version = "4"
Access Token (required) CIVI_USER_KEY user_key=... user-key = "..."
Site Token (required for v3) CIVI_SITE_KEY site_key=... site-key = "..."
Log File CIVI_LOG_FILE log_file=/tmp/civipy.log log-file = "/tmp/civipy.log"
Log Level CIVI_LOG_LEVEL log_level=WARNING log-level = "WARNING"
Config File CIVI_CONFIG

Connection

The Connection setting lets you specify the URL of your REST API, or the cv or drush or wp-cli executable on your file system. If "http" is found in the setting, the system will use http calls to the REST API. If the string "drush" is found, it will use drush. If the string "wp" is found, it will use wp-cli. And if none of these are found, it will attempt to call the cv command line API.

API Version

Set to "3" to use the CiviCRM v3 API, or "4" (the default) to use the CiviCRM v4 API.

Log File

To log to a file instead of the screen, set the Log File setting to the file path you want to log to.

Config File

You can specify in an environment variable either a directory to find a .civipy configuration file in, or a file to read as a .civipy configuration file.

Usage

There is a Django-style .objects attribute on each record model with filter, values, order_by, and all methods for querying; and create, delete, and update methods for making changes. Model instances also have save and delete methods.

from civipy import CiviContact

contact = CiviContact.objects.filter(email_primary__email="ana@ananelson.com")[0]
contact.nick_name = "Ana"
contact.save()

Each CiviCRM Entity is represented by a subclass of CiviCRMBase; if you need an entity that is not in the project, you can easily add it by subclassing CiviCRMBase and naming it the entity name prepended with "Civi", e.g.

import civipy

class CiviNewEntity(civipy.CiviCRMBase):
    pass

Copyright & License

civipy Copyright © 2020 Ana Nelson

Licensed under the GPL v3

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

https://www.gnu.org/licenses/gpl-3.0.txt

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

civipy-0.0.7.tar.gz (35.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

civipy-0.0.7-py3-none-any.whl (38.8 kB view details)

Uploaded Python 3

File details

Details for the file civipy-0.0.7.tar.gz.

File metadata

  • Download URL: civipy-0.0.7.tar.gz
  • Upload date:
  • Size: 35.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for civipy-0.0.7.tar.gz
Algorithm Hash digest
SHA256 33269601bf3d40c3d8cd75945f77198905f352d84de220946158db7cc5b8cd9d
MD5 05b5fceb9db91745319badb62f042c33
BLAKE2b-256 befd024e9a89797263bbf168edfd3fd3c0708b6d25ce664e2737118d08cfcab7

See more details on using hashes here.

File details

Details for the file civipy-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: civipy-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 38.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for civipy-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e6b77f3339f4c882ad2567f916aa893a943316d0f84a116d3b56252d61be06e0
MD5 3052baa7802a40f68f24352efd2caf7f
BLAKE2b-256 b4d689b6bd09c476e173a4a37455d36d3e6b0320ba8bedd23aa5d465310c0bbf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page