Skip to main content

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

Metadata

Release files for civipy 0.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 civipy 0.0.7
File Size Uploaded
civipy-0.0.7.tar.gz 35.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for civipy 0.0.7
File Interpreter ABI Platform
civipy-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 73.8 kB

Release files / civipy-0.0.7.tar.gz

Download URL civipy-0.0.7.tar.gz
Size 35.0 kB
Tags Source
SHA-256 checksum
How to use checksums
33269601bf3d40c3d8cd75945f77198905f352d84de220946158db7cc5b8cd9d
BLAKE2b-256 checksum
How to use checksums
befd024e9a89797263bbf168edfd3fd3c0708b6d25ce664e2737118d08cfcab7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / civipy-0.0.7-py3-none-any.whl

Download URL civipy-0.0.7-py3-none-any.whl
Size 38.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6b77f3339f4c882ad2567f916aa893a943316d0f84a116d3b56252d61be06e0
BLAKE2b-256 checksum
How to use checksums
b4d689b6bd09c476e173a4a37455d36d3e6b0320ba8bedd23aa5d465310c0bbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.2

2 release files

0.0.1

2 release files

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