Utilities

Utility methods for Django Heroku Connect.

class heroku_connect.utils.WriteAlgorithm(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
heroku_connect.utils.create_heroku_connect_schema(using='default')[source]

Create Heroku Connect schema.

Note

This function is only meant to be used for local development. In a production environment the schema will be created by Heroku Connect.

Parameters:

using (str) – Alias for database connection.

Returns:

True if the schema was created, False if the

schema already exists.

Return type:

bool

heroku_connect.utils.get_connected_model_for_table_name(table_name)[source]

Return a connected model’s table name (which read and written to by Heroku Connect).

heroku_connect.utils.get_connection(connection_id, deep=False)[source]

Get Heroku Connection connection information.

For more details check the link - https://devcenter.heroku.com/articles/heroku-connect-api#step-8-monitor-the-connection-and-mapping-status

Sample response from API call is below:

{
    "id": "<connection_id>",
    "name": "<app_name>",
    "resource_name": "<resource_name>",
    "schema_name": "salesforce",
    "db_key": "DATABASE_URL",
    "state": "IDLE",
    "mappings":[
        {
            "id": "<mapping_id>",
            "object_name": "Account",
            "state": "SCHEMA_CHANGED",
            …
        },
        {
            "id": "<mapping_id>",
            "object_name": "Contact",
            "state": "SCHEMA_CHANGED",
            …
        },
        …
    ]
    …
}
Parameters:
  • connection_id (str) – ID for Heroku Connect’s connection.

  • deep (bool) – Return information about the connection’s mappings, in addition to the connection itself. Defaults to False.

Returns:

Heroku Connection connection information.

Return type:

dict

Raises:
  • requests.HTTPError – If an error occurred when accessing the connection detail API.

  • ValueError – If response is not a valid JSON.

heroku_connect.utils.get_connections(app)[source]

Return all Heroku Connect connections setup with the given application.

For more details check the link - https://devcenter.heroku.com/articles/heroku-connect-api#step-4-retrieve-the-new-connection-s-id

Sample response from the API call is below:

{
    "count": 1,
    "results":[{
        "id": "<connection_id>",
        "name": "<app_name>",
        "resource_name": "<resource_name>",
        …
    }],
    …
}
Parameters:

app (str) – Heroku application name.

Returns:

List of all Heroku Connect connections associated with the Heroku application.

Return type:

List[dict]

Raises:
  • requests.HTTPError – If an error occurred when accessing the connections API.

  • ValueError – If response is not a valid JSON.

heroku_connect.utils.get_heroku_connect_models()[source]

Return all registered Heroku Connect Models.

Returns:

All registered models that are subclasses of .HerokuConnectModel. Abstract models are excluded, since they are not registered.

Return type:

(Iterator)

heroku_connect.utils.get_mapping(version=1, exported_at=None, app_name=None)[source]

Return Heroku Connect mapping for the entire project.

Parameters:
  • version (int) – Version of the Heroku Connect mapping, default: 1.

  • exported_at (datetime.datetime) – Time the export was created, default is now().

  • app_name (str) – Name of Heroku application associated with Heroku Connect the add-on.

Returns:

Heroku Connect mapping.

Return type:

dict

Note

The version does not need to be incremented. Exports from the Heroku Connect website will always have the version number 1.

heroku_connect.utils.import_mapping(connection_id, mapping)[source]

Import Heroku Connection mapping for given connection.

Parameters:
  • connection_id (str) – Heroku Connection connection ID.

  • mapping (dict) – Heroku Connect mapping.

Raises:
  • requests.HTTPError – If an error occurs uploading the mapping.

  • ValueError – If the mapping is not JSON serializable.

Link the connection to your Heroku user account.

https://devcenter.heroku.com/articles/heroku-connect-api#step-3-link-the-new-add-on-to-your-heroku-user-account