moesif-gcp-function


Namemoesif-gcp-function JSON
Version 0.0.1 PyPI version JSON
download
home_pagehttps://www.moesif.com/docs/server-integration/gcp-function-python/
SummaryMoesif Middleware to automatically log API calls from GCP Cloud functions
upload_time2024-01-23 05:27:01
maintainer
docs_urlNone
authorMoesif, Inc
requires_python
licenseApache Software License
keywords moesif gcp serverless api gateway function debug logging trace analytics
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Moesif GCP Function Middleware

[![Built For][ico-built-for]][link-built-for]
[![Software License][ico-license]][link-license]
[![Source Code][ico-source]][link-source]

Middleware (Python) to automatically log API calls from GCP Cloud functions
and sends to [Moesif](https://www.moesif.com) for API analytics and log analysis. 

Designed for APIs that are hosted on GCP Cloud functions using Google API Gateway as a trigger.

## How to install

```shell
pip install moesif_gcp_function
```

## How to use

### 1. Add middleware to your Cloud function application.

```python
from moesif_gcp_function.middleware import MoesifLogger
import functions_framework

moesif_options = {
    'LOG_BODY': True
}

@MoesifLogger(moesif_options)
@functions_framework.http
def hello_get(request):
  return "Hello World!"
```

### 2. Set MOESIF_APPLICATION_ID environment variable 

Add a new environment variable with the name `MOESIF_APPLICATION_ID` and the value being your Moesif application id,
which can be found in the [_Moesif Portal_](https://www.moesif.com/).
After signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps. 

You can always find your Moesif Application Id at any time by logging 
into the [_Moesif Portal_](https://www.moesif.com/), click on the top right menu,
 and then clicking _Installation_.

### 3. Trigger your API
Grab the URL to your API Gateway and make some calls using a tool like Postman or CURL. 

## Optional: Capturing outgoing API calls
If you want to capture all outgoing API calls from your Python Cloud function to third parties like
Stripe or to your own dependencies, call `start_capture_outgoing()` to start capturing. This mechanism works by 
patching the [Requests](https://requests.readthedocs.io/en/master/) 

```python
from moesif_gcp_function.middleware import *
start_capture_outgoing(moesif_options) # moesif_options are the configuration options.
```

## Configuration options

### __`IDENTIFY_USER`__

Type: `(request, response) => String`

`IDENTIFY_USER` is a function that takes Flask [request](https://tedboy.github.io/flask/generated/generated/flask.Request.html) and [response](https://tedboy.github.io/flask/generated/generated/flask.Response.html) objects as arguments
and returns a user_id. This enables Moesif to attribute API requests to individual unique users
so you can understand who calling your API. This can be used simultaneously with `IDENTIFY_COMPANY`
to track both individual customers and the companies their a part of.


```python
def identify_user(request, response):
  # your code here, must return a string
  return 
```

### __`IDENTIFY_COMPANY`__

Type: `(request, response) => String`

`IDENTIFY_COMPANY` is a function that takes Flask [request](https://tedboy.github.io/flask/generated/generated/flask.Request.html) and [response](https://tedboy.github.io/flask/generated/generated/flask.Response.html) objects as arguments
and returns a company_id. If your business is B2B, this enables Moesif to attribute 
API requests to specific companies or organizations so you can understand which accounts are 
calling your API. This can be used simultaneously with `IDENTIFY_USER` to track both 
individual customers and the companies their a part of. 


```python
def identify_company(request, response):
  # your code here, must return a string
  return '7890'
}
```

### __`GET_SESSION_TOKEN`__

Type: `(request, response) => String`

`GET_SESSION_TOKEN` a function that takes Flask [request](https://tedboy.github.io/flask/generated/generated/flask.Request.html) and [response](https://tedboy.github.io/flask/generated/generated/flask.Response.html) objects as arguments and returns a
session token (i.e. such as an API key).


```python
def get_session_token(request, response):
    # your code here, must return a string.
    return 'XXXXXXXXX'
```

### __`GET_API_VERSION`__

Type: `(request, response) => String`

`GET_API_VERSION` is a function that takes Flask [request](https://tedboy.github.io/flask/generated/generated/flask.Request.html) and [response](https://tedboy.github.io/flask/generated/generated/flask.Response.html) objects as arguments and
returns a string to tag requests with a specific version of your API.


```python
def get_api_version(request, response):
  # your code here. must return a string.
  return '1.0.0'
```

### __`GET_METADATA`__

Type: `(request, response) => dict`

`GET_METADATA` is a function that takes Flask [request](https://tedboy.github.io/flask/generated/generated/flask.Request.html) and [response](https://tedboy.github.io/flask/generated/generated/flask.Response.html) objects as arguments and returns an object that allows you to add custom metadata that will be associated with the request. The metadata must be a simple python object that can be converted to JSON. For example, you may want to save a function_name, or a trace_id with the request.


```python
def get_metadata(request, response):
  # your code here:
  return {
        'trace_id': "trace_id_XX",
        'function_name': "function_name"
    }
```

### __`SKIP`__

Type: `(request, response) => Boolean`

`SKIP` is a function that takes Flask [request](https://tedboy.github.io/flask/generated/generated/flask.Request.html) and [response](https://tedboy.github.io/flask/generated/generated/flask.Response.html) objects as arguments and returns true
if the event should be skipped (i.e. not logged)


```python
def should_skip(request, response):
    # your code here. must return a boolean.
    return "skip" in request.url
```

### __`MASK_EVENT_MODEL`__

Type: `MoesifEventModel => MoesifEventModel`

`MASK_EVENT_MODEL` is a function that takes the final Moesif event model as an argument before being sent to Moesif. With maskContent, you can make modifications to headers or body such as removing certain header or body fields.

```python
def mask_event(eventmodel):
  # remove any field that you don't want to be sent to Moesif.
  return eventmodel
 ```

### __`DEBUG`__

Type: `Boolean`

Set to true to print debug logs if you're having integration issues. 

### __`LOG_BODY`__

Type: `Boolean`

`LOG_BODY` is default to true, set to false to remove logging request and response body to Moesif.

## Options for logging outgoing calls

The options below are applied to outgoing API calls. The request and response objects passed in are  [Requests](https://requests.readthedocs.io/en/master/user/advanced/#request-and-response-objects) request and [Response](https://requests.readthedocs.io/en/master/user/advanced/#request-and-response-objects) response objects.

### __`SKIP_OUTGOING`__
(optional) _(req, res) => boolean_, a function that takes a [Requests](https://requests.readthedocs.io/en/master/) request and response,
and returns true if you want to skip this particular event.

### __`IDENTIFY_USER_OUTGOING`__
(optional, but highly recommended) _(req, res) => string_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and returns a string that is the user id used by your system. While Moesif tries to identify users automatically,
but different frameworks and your implementation might be very different, it would be helpful and much more accurate to provide this function.

### __`IDENTIFY_COMPANY_OUTGOING`__
(optional) _(req, res) => string_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and returns a string that is the company id for this event.

### __`GET_METADATA_OUTGOING`__
(optional) _(req, res) => dictionary_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and
returns a dictionary (must be able to be encoded into JSON). This allows
to associate this event with custom metadata. For example, you may want to save a VM instance_id, a trace_id, or a tenant_id with the request.

### __`GET_SESSION_TOKEN_OUTGOING`__
(optional) _(req, res) => string_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and returns a string that is the session token for this event. Again, Moesif tries to get the session token automatically, but if you setup is very different from standard, this function will be very help for tying events together, and help you replay the events.

### __`LOG_BODY_OUTGOING`__
(optional) _boolean_, default True, Set to False to remove logging request and response body.

## Update User

### Update A Single User
Create or update a user profile in Moesif.
The metadata field can be any customer demographic or other info you want to store.
Only the `user_id` field is required.
For details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-a-user).

```python
from moesif_gcp_function.middleware import *

moesif_options = {
    'LOG_BODY': True,
    'DEBUG': True,
}

# Only user_id is required.
# Campaign object is optional, but useful if you want to track ROI of acquisition channels
# See https://www.moesif.com/docs/api#users for campaign schema
# metadata can be any custom object
user = {
  'user_id': '12345',
  'company_id': '67890', # If set, associate user with a company object
  'campaign': {
    'utm_source': 'google',
    'utm_medium': 'cpc',
    'utm_campaign': 'adwords',
    'utm_term': 'api+tooling',
    'utm_content': 'landing'
  },
  'metadata': {
    'email': 'john@acmeinc.com',
    'first_name': 'John',
    'last_name': 'Doe',
    'title': 'Software Engineer',
    'sales_info': {
        'stage': 'Customer',
        'lifetime_value': 24000,
        'account_owner': 'mary@contoso.com'
    },
  }
}

update_user(user, moesif_options)
```

### Update Users in Batch
Similar to update_user, but used to update a list of users in one batch.
Only the `user_id` field is required.
For details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-users-in-batch).

```python
from moesif_gcp_function.middleware import *

moesif_options = {
    'LOG_BODY': True,
    'DEBUG': True,
}

userA = {
  'user_id': '12345',
  'company_id': '67890', # If set, associate user with a company object
  'metadata': {
    'email': 'john@acmeinc.com',
    'first_name': 'John',
    'last_name': 'Doe',
    'title': 'Software Engineer',
    'sales_info': {
        'stage': 'Customer',
        'lifetime_value': 24000,
        'account_owner': 'mary@contoso.com'
    },
  }
}

userB = {
  'user_id': '54321',
  'company_id': '67890', # If set, associate user with a company object
  'metadata': {
    'email': 'mary@acmeinc.com',
    'first_name': 'Mary',
    'last_name': 'Jane',
    'title': 'Software Engineer',
    'sales_info': {
        'stage': 'Customer',
        'lifetime_value': 48000,
        'account_owner': 'mary@contoso.com'
    },
  }
}
update_users_batch([userA, userB], moesif_options)
```

## Update Company

### Update A Single Company
Create or update a company profile in Moesif.
The metadata field can be any company demographic or other info you want to store.
Only the `company_id` field is required.
For details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-a-company).

```python
from moesif_gcp_function.middleware import *

moesif_options = {
    'LOG_BODY': True,
    'DEBUG': True,
}

# Only company_id is required.
# Campaign object is optional, but useful if you want to track ROI of acquisition channels
# See https://www.moesif.com/docs/api#update-a-company for campaign schema
# metadata can be any custom object
company = {
  'company_id': '67890',
  'company_domain': 'acmeinc.com', # If domain is set, Moesif will enrich your profiles with publicly available info
  'campaign': {
    'utm_source': 'google',
    'utm_medium': 'cpc',
    'utm_campaign': 'adwords',
    'utm_term': 'api+tooling',
    'utm_content': 'landing'
  },
  'metadata': {
    'org_name': 'Acme, Inc',
    'plan_name': 'Free',
    'deal_stage': 'Lead',
    'mrr': 24000,
    'demographics': {
        'alexa_ranking': 500000,
        'employee_count': 47
    },
  }
}

update_company(company, moesif_options)
```

### Update Companies in Batch
Similar to update_company, but used to update a list of companies in one batch.
Only the `company_id` field is required.
For details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-companies-in-batch).

```python
from moesif_gcp_function.middleware import *

moesif_options = {
    'LOG_BODY': True,
    'DEBUG': True,
}

companyA = {
  'company_id': '67890',
  'company_domain': 'acmeinc.com', # If domain is set, Moesif will enrich your profiles with publicly available info
  'metadata': {
    'org_name': 'Acme, Inc',
    'plan_name': 'Free',
    'deal_stage': 'Lead',
    'mrr': 24000,
    'demographics': {
        'alexa_ranking': 500000,
        'employee_count': 47
    },
  }
}

companyB = {
  'company_id': '09876',
  'company_domain': 'contoso.com', # If domain is set, Moesif will enrich your profiles with publicly available info
  'metadata': {
    'org_name': 'Contoso, Inc',
    'plan_name': 'Free',
    'deal_stage': 'Lead',
    'mrr': 48000,
    'demographics': {
        'alexa_ranking': 500000,
        'employee_count': 53
    },
  }
}

update_companies_batch([companyA, companyB], moesif_options)
```

## Examples

- [A complete example is available on GitHub](https://github.com/Moesif/moesif-gcp-function-python-example).

## Other integrations

To view more documentation on integration options, please visit __[the Integration Options Documentation](https://www.moesif.com/docs/getting-started/integration-options/).__

[ico-built-for]: https://img.shields.io/badge/built%20for-gcp%20function-blue.svg
[ico-license]: https://img.shields.io/badge/License-Apache%202.0-green.svg
[ico-source]: https://img.shields.io/github/last-commit/moesif/moesif-gcp-function-python.svg?style=social

[link-built-for]: https://cloud.google.com/functions?hl=en
[link-license]: https://raw.githubusercontent.com/Moesif/moesif-gcp-function-python/master/LICENSE
[link-source]: https://github.com/moesif/moesif-gcp-function-python

            

Raw data

            {
    "_id": null,
    "home_page": "https://www.moesif.com/docs/server-integration/gcp-function-python/",
    "name": "moesif-gcp-function",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "moesif gcp serverless api gateway function debug logging trace analytics",
    "author": "Moesif, Inc",
    "author_email": "keyur@moesif.com",
    "download_url": "https://files.pythonhosted.org/packages/7e/2c/e6c1569ca4025fb3a08b5a2d84e1bc55e3fee85ee4f055584553fe1a8d54/moesif_gcp_function-0.0.1.tar.gz",
    "platform": null,
    "description": "# Moesif GCP Function Middleware\n\n[![Built For][ico-built-for]][link-built-for]\n[![Software License][ico-license]][link-license]\n[![Source Code][ico-source]][link-source]\n\nMiddleware (Python) to automatically log API calls from GCP Cloud functions\nand sends to [Moesif](https://www.moesif.com) for API analytics and log analysis. \n\nDesigned for APIs that are hosted on GCP Cloud functions using Google API Gateway as a trigger.\n\n## How to install\n\n```shell\npip install moesif_gcp_function\n```\n\n## How to use\n\n### 1. Add middleware to your Cloud function application.\n\n```python\nfrom moesif_gcp_function.middleware import MoesifLogger\nimport functions_framework\n\nmoesif_options = {\n    'LOG_BODY': True\n}\n\n@MoesifLogger(moesif_options)\n@functions_framework.http\ndef hello_get(request):\n  return \"Hello World!\"\n```\n\n### 2. Set MOESIF_APPLICATION_ID environment variable \n\nAdd a new environment variable with the name `MOESIF_APPLICATION_ID` and the value being your Moesif application id,\nwhich can be found in the [_Moesif Portal_](https://www.moesif.com/).\nAfter signing up for a Moesif account, your Moesif Application Id will be displayed during the onboarding steps. \n\nYou can always find your Moesif Application Id at any time by logging \ninto the [_Moesif Portal_](https://www.moesif.com/), click on the top right menu,\n and then clicking _Installation_.\n\n### 3. Trigger your API\nGrab the URL to your API Gateway and make some calls using a tool like Postman or CURL. \n\n## Optional: Capturing outgoing API calls\nIf you want to capture all outgoing API calls from your Python Cloud function to third parties like\nStripe or to your own dependencies, call `start_capture_outgoing()` to start capturing. This mechanism works by \npatching the [Requests](https://requests.readthedocs.io/en/master/) \n\n```python\nfrom moesif_gcp_function.middleware import *\nstart_capture_outgoing(moesif_options) # moesif_options are the configuration options.\n```\n\n## Configuration options\n\n### __`IDENTIFY_USER`__\n\nType: `(request, response) => String`\n\n`IDENTIFY_USER` is a function that takes Flask [request](https://tedboy.github.io/flask/generated/generated/flask.Request.html) and [response](https://tedboy.github.io/flask/generated/generated/flask.Response.html) objects as arguments\nand returns a user_id. This enables Moesif to attribute API requests to individual unique users\nso you can understand who calling your API. This can be used simultaneously with `IDENTIFY_COMPANY`\nto track both individual customers and the companies their a part of.\n\n\n```python\ndef identify_user(request, response):\n  # your code here, must return a string\n  return \n```\n\n### __`IDENTIFY_COMPANY`__\n\nType: `(request, response) => String`\n\n`IDENTIFY_COMPANY` is a function that takes Flask [request](https://tedboy.github.io/flask/generated/generated/flask.Request.html) and [response](https://tedboy.github.io/flask/generated/generated/flask.Response.html) objects as arguments\nand returns a company_id. If your business is B2B, this enables Moesif to attribute \nAPI requests to specific companies or organizations so you can understand which accounts are \ncalling your API. This can be used simultaneously with `IDENTIFY_USER` to track both \nindividual customers and the companies their a part of. \n\n\n```python\ndef identify_company(request, response):\n  # your code here, must return a string\n  return '7890'\n}\n```\n\n### __`GET_SESSION_TOKEN`__\n\nType: `(request, response) => String`\n\n`GET_SESSION_TOKEN` a function that takes Flask [request](https://tedboy.github.io/flask/generated/generated/flask.Request.html) and [response](https://tedboy.github.io/flask/generated/generated/flask.Response.html) objects as arguments and returns a\nsession token (i.e. such as an API key).\n\n\n```python\ndef get_session_token(request, response):\n    # your code here, must return a string.\n    return 'XXXXXXXXX'\n```\n\n### __`GET_API_VERSION`__\n\nType: `(request, response) => String`\n\n`GET_API_VERSION` is a function that takes Flask [request](https://tedboy.github.io/flask/generated/generated/flask.Request.html) and [response](https://tedboy.github.io/flask/generated/generated/flask.Response.html) objects as arguments and\nreturns a string to tag requests with a specific version of your API.\n\n\n```python\ndef get_api_version(request, response):\n  # your code here. must return a string.\n  return '1.0.0'\n```\n\n### __`GET_METADATA`__\n\nType: `(request, response) => dict`\n\n`GET_METADATA` is a function that takes Flask [request](https://tedboy.github.io/flask/generated/generated/flask.Request.html) and [response](https://tedboy.github.io/flask/generated/generated/flask.Response.html) objects as arguments and returns an object that allows you to add custom metadata that will be associated with the request. The metadata must be a simple python object that can be converted to JSON. For example, you may want to save a function_name, or a trace_id with the request.\n\n\n```python\ndef get_metadata(request, response):\n  # your code here:\n  return {\n        'trace_id': \"trace_id_XX\",\n        'function_name': \"function_name\"\n    }\n```\n\n### __`SKIP`__\n\nType: `(request, response) => Boolean`\n\n`SKIP` is a function that takes Flask [request](https://tedboy.github.io/flask/generated/generated/flask.Request.html) and [response](https://tedboy.github.io/flask/generated/generated/flask.Response.html) objects as arguments and returns true\nif the event should be skipped (i.e. not logged)\n\n\n```python\ndef should_skip(request, response):\n    # your code here. must return a boolean.\n    return \"skip\" in request.url\n```\n\n### __`MASK_EVENT_MODEL`__\n\nType: `MoesifEventModel => MoesifEventModel`\n\n`MASK_EVENT_MODEL` is a function that takes the final Moesif event model as an argument before being sent to Moesif. With maskContent, you can make modifications to headers or body such as removing certain header or body fields.\n\n```python\ndef mask_event(eventmodel):\n  # remove any field that you don't want to be sent to Moesif.\n  return eventmodel\n ```\n\n### __`DEBUG`__\n\nType: `Boolean`\n\nSet to true to print debug logs if you're having integration issues. \n\n### __`LOG_BODY`__\n\nType: `Boolean`\n\n`LOG_BODY` is default to true, set to false to remove logging request and response body to Moesif.\n\n## Options for logging outgoing calls\n\nThe options below are applied to outgoing API calls. The request and response objects passed in are  [Requests](https://requests.readthedocs.io/en/master/user/advanced/#request-and-response-objects) request and [Response](https://requests.readthedocs.io/en/master/user/advanced/#request-and-response-objects) response objects.\n\n### __`SKIP_OUTGOING`__\n(optional) _(req, res) => boolean_, a function that takes a [Requests](https://requests.readthedocs.io/en/master/) request and response,\nand returns true if you want to skip this particular event.\n\n### __`IDENTIFY_USER_OUTGOING`__\n(optional, but highly recommended) _(req, res) => string_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and returns a string that is the user id used by your system. While Moesif tries to identify users automatically,\nbut different frameworks and your implementation might be very different, it would be helpful and much more accurate to provide this function.\n\n### __`IDENTIFY_COMPANY_OUTGOING`__\n(optional) _(req, res) => string_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and returns a string that is the company id for this event.\n\n### __`GET_METADATA_OUTGOING`__\n(optional) _(req, res) => dictionary_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and\nreturns a dictionary (must be able to be encoded into JSON). This allows\nto associate this event with custom metadata. For example, you may want to save a VM instance_id, a trace_id, or a tenant_id with the request.\n\n### __`GET_SESSION_TOKEN_OUTGOING`__\n(optional) _(req, res) => string_, a function that takes [Requests](https://requests.readthedocs.io/en/master/) request and response, and returns a string that is the session token for this event. Again, Moesif tries to get the session token automatically, but if you setup is very different from standard, this function will be very help for tying events together, and help you replay the events.\n\n### __`LOG_BODY_OUTGOING`__\n(optional) _boolean_, default True, Set to False to remove logging request and response body.\n\n## Update User\n\n### Update A Single User\nCreate or update a user profile in Moesif.\nThe metadata field can be any customer demographic or other info you want to store.\nOnly the `user_id` field is required.\nFor details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-a-user).\n\n```python\nfrom moesif_gcp_function.middleware import *\n\nmoesif_options = {\n    'LOG_BODY': True,\n    'DEBUG': True,\n}\n\n# Only user_id is required.\n# Campaign object is optional, but useful if you want to track ROI of acquisition channels\n# See https://www.moesif.com/docs/api#users for campaign schema\n# metadata can be any custom object\nuser = {\n  'user_id': '12345',\n  'company_id': '67890', # If set, associate user with a company object\n  'campaign': {\n    'utm_source': 'google',\n    'utm_medium': 'cpc',\n    'utm_campaign': 'adwords',\n    'utm_term': 'api+tooling',\n    'utm_content': 'landing'\n  },\n  'metadata': {\n    'email': 'john@acmeinc.com',\n    'first_name': 'John',\n    'last_name': 'Doe',\n    'title': 'Software Engineer',\n    'sales_info': {\n        'stage': 'Customer',\n        'lifetime_value': 24000,\n        'account_owner': 'mary@contoso.com'\n    },\n  }\n}\n\nupdate_user(user, moesif_options)\n```\n\n### Update Users in Batch\nSimilar to update_user, but used to update a list of users in one batch.\nOnly the `user_id` field is required.\nFor details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-users-in-batch).\n\n```python\nfrom moesif_gcp_function.middleware import *\n\nmoesif_options = {\n    'LOG_BODY': True,\n    'DEBUG': True,\n}\n\nuserA = {\n  'user_id': '12345',\n  'company_id': '67890', # If set, associate user with a company object\n  'metadata': {\n    'email': 'john@acmeinc.com',\n    'first_name': 'John',\n    'last_name': 'Doe',\n    'title': 'Software Engineer',\n    'sales_info': {\n        'stage': 'Customer',\n        'lifetime_value': 24000,\n        'account_owner': 'mary@contoso.com'\n    },\n  }\n}\n\nuserB = {\n  'user_id': '54321',\n  'company_id': '67890', # If set, associate user with a company object\n  'metadata': {\n    'email': 'mary@acmeinc.com',\n    'first_name': 'Mary',\n    'last_name': 'Jane',\n    'title': 'Software Engineer',\n    'sales_info': {\n        'stage': 'Customer',\n        'lifetime_value': 48000,\n        'account_owner': 'mary@contoso.com'\n    },\n  }\n}\nupdate_users_batch([userA, userB], moesif_options)\n```\n\n## Update Company\n\n### Update A Single Company\nCreate or update a company profile in Moesif.\nThe metadata field can be any company demographic or other info you want to store.\nOnly the `company_id` field is required.\nFor details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-a-company).\n\n```python\nfrom moesif_gcp_function.middleware import *\n\nmoesif_options = {\n    'LOG_BODY': True,\n    'DEBUG': True,\n}\n\n# Only company_id is required.\n# Campaign object is optional, but useful if you want to track ROI of acquisition channels\n# See https://www.moesif.com/docs/api#update-a-company for campaign schema\n# metadata can be any custom object\ncompany = {\n  'company_id': '67890',\n  'company_domain': 'acmeinc.com', # If domain is set, Moesif will enrich your profiles with publicly available info\n  'campaign': {\n    'utm_source': 'google',\n    'utm_medium': 'cpc',\n    'utm_campaign': 'adwords',\n    'utm_term': 'api+tooling',\n    'utm_content': 'landing'\n  },\n  'metadata': {\n    'org_name': 'Acme, Inc',\n    'plan_name': 'Free',\n    'deal_stage': 'Lead',\n    'mrr': 24000,\n    'demographics': {\n        'alexa_ranking': 500000,\n        'employee_count': 47\n    },\n  }\n}\n\nupdate_company(company, moesif_options)\n```\n\n### Update Companies in Batch\nSimilar to update_company, but used to update a list of companies in one batch.\nOnly the `company_id` field is required.\nFor details, visit the [Python API Reference](https://www.moesif.com/docs/api?python#update-companies-in-batch).\n\n```python\nfrom moesif_gcp_function.middleware import *\n\nmoesif_options = {\n    'LOG_BODY': True,\n    'DEBUG': True,\n}\n\ncompanyA = {\n  'company_id': '67890',\n  'company_domain': 'acmeinc.com', # If domain is set, Moesif will enrich your profiles with publicly available info\n  'metadata': {\n    'org_name': 'Acme, Inc',\n    'plan_name': 'Free',\n    'deal_stage': 'Lead',\n    'mrr': 24000,\n    'demographics': {\n        'alexa_ranking': 500000,\n        'employee_count': 47\n    },\n  }\n}\n\ncompanyB = {\n  'company_id': '09876',\n  'company_domain': 'contoso.com', # If domain is set, Moesif will enrich your profiles with publicly available info\n  'metadata': {\n    'org_name': 'Contoso, Inc',\n    'plan_name': 'Free',\n    'deal_stage': 'Lead',\n    'mrr': 48000,\n    'demographics': {\n        'alexa_ranking': 500000,\n        'employee_count': 53\n    },\n  }\n}\n\nupdate_companies_batch([companyA, companyB], moesif_options)\n```\n\n## Examples\n\n- [A complete example is available on GitHub](https://github.com/Moesif/moesif-gcp-function-python-example).\n\n## Other integrations\n\nTo view more documentation on integration options, please visit __[the Integration Options Documentation](https://www.moesif.com/docs/getting-started/integration-options/).__\n\n[ico-built-for]: https://img.shields.io/badge/built%20for-gcp%20function-blue.svg\n[ico-license]: https://img.shields.io/badge/License-Apache%202.0-green.svg\n[ico-source]: https://img.shields.io/github/last-commit/moesif/moesif-gcp-function-python.svg?style=social\n\n[link-built-for]: https://cloud.google.com/functions?hl=en\n[link-license]: https://raw.githubusercontent.com/Moesif/moesif-gcp-function-python/master/LICENSE\n[link-source]: https://github.com/moesif/moesif-gcp-function-python\n",
    "bugtrack_url": null,
    "license": "Apache Software License",
    "summary": "Moesif Middleware to automatically log API calls from GCP Cloud functions",
    "version": "0.0.1",
    "project_urls": {
        "Homepage": "https://www.moesif.com/docs/server-integration/gcp-function-python/"
    },
    "split_keywords": [
        "moesif",
        "gcp",
        "serverless",
        "api",
        "gateway",
        "function",
        "debug",
        "logging",
        "trace",
        "analytics"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "faee7e06b2f3ad7c9bcc347cdbbfbceff3f3caff8e3e9491511e9583ac4280b2",
                "md5": "d88697e01000684b6799eb87ccbed18d",
                "sha256": "395823d5b0e9c2acd737dd11d0baefd4156aa811b77597adce0458a1515f35c8"
            },
            "downloads": -1,
            "filename": "moesif_gcp_function-0.0.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d88697e01000684b6799eb87ccbed18d",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 17181,
            "upload_time": "2024-01-23T05:26:58",
            "upload_time_iso_8601": "2024-01-23T05:26:58.771212Z",
            "url": "https://files.pythonhosted.org/packages/fa/ee/7e06b2f3ad7c9bcc347cdbbfbceff3f3caff8e3e9491511e9583ac4280b2/moesif_gcp_function-0.0.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7e2ce6c1569ca4025fb3a08b5a2d84e1bc55e3fee85ee4f055584553fe1a8d54",
                "md5": "dbeac5a9ee3799d6c893cae5e8b5ad32",
                "sha256": "67f283349708ccfaf009f51d5674edb9ce6ada711eeeff3772767e29244dfe62"
            },
            "downloads": -1,
            "filename": "moesif_gcp_function-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "dbeac5a9ee3799d6c893cae5e8b5ad32",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 19588,
            "upload_time": "2024-01-23T05:27:01",
            "upload_time_iso_8601": "2024-01-23T05:27:01.098865Z",
            "url": "https://files.pythonhosted.org/packages/7e/2c/e6c1569ca4025fb3a08b5a2d84e1bc55e3fee85ee4f055584553fe1a8d54/moesif_gcp_function-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-23 05:27:01",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "moesif-gcp-function"
}
        
Elapsed time: 0.43447s