PeekBatch in python azure - python

Is there a python API for reading all message present in a queue at that time? I found the api for .net:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.servicebus.messaging.queueclient.peekbatch?view=azure-dotnet#Microsoft_ServiceBus_Messaging_QueueClient_PeekBatch_System_Int32_

As I known, Azure SDK for Python is wrapped Azure REST API, there is only a REST API to peek a message at one time, so the answer is no.
And there are some issues for this needs on Azure GitHub repo as below, the offical team recommended using AMQP instead of HTTP to peek messages.
Add support ReceiveBatch in servicebus.py
ServiceBus Batch Receive support
Hope it helps.

Related

What is the best practice for authenticating a HTTP request to a Python Azure Function endpoint (Azure AD JWT)?

Could anyone tell me what is the current best practice for authenticating a HTTP request to a Python Azure Function endpoint with Azure AD? The HTTP request is made from an SPA browser client including an attached JWT bearer token. I am not using any role-based authentication, just the basic one with an access scope.
If this was a C# function this would be quite straightforward because I could use the SDK provided by Microsoft.Identity.Web. However, I am not aware of anything similar in the case of Python, nor did I find any useful example in the Azure Samples GitHub repo.
I am also not asking about the Azure AD configuration, just the necessary code in the function itself.
However, I am not aware of anything similar in the case of Python, nor
did I find any useful example in the Azure Samples GitHub repo.
To do that in python Azure function to secure with Azure AD you can find the steps with sample code as mentioned here in GitHub .
For more information please refer the below links:
. azure-functions-python-library | GitHub .
. Python Azure Function Web API secured by Azure AD| MS DOC .

How to delivery content (video) by download with python sdk?

i'm a python developer, inexperienced in microsoft azure services.
For a client I have to allow downloading of videos using the azure media service (video streaming). I did find information on the subject in the documentation (https://learn.microsoft.com/en-us/azure/media-services/previous/media-services-deliver-asset-download), but I want to get there using python (so either the rest azure api, or the python sdk).
I'm starting to believe it's impossible.
I need your help please.
Everything you need to do should be completely possible with the Python SDK.
I do not recommend using the REST API directly! It does not have any built in retry policies that Azure Resource Management API requires. You can get into issues with that in production - unless you know what you are doing and roll your own retry logic.
Use the official Python SDK client for Media Services only.
Also, the link above for the REST API is pointing to the legacy v2 API - do not use that now. Use the latest v3 SDK client only here -
pip install azure-mgmt-media
We have a limited number of Python samples up here that show how to use the client SDK for Python - https://github.com/Azure-Samples/media-services-v3-python
None of us on the team are Python experts, and we don't seem to get a lot of contributions to that repo - so it is not anywhere near as comprehensive as our .NET samples here - https://github.com/Azure-Samples/media-services-v3-dotnet
But keep in mind that all the Azure SDK's are just auto generated off the REST API Swagger (Open API) - so they all use the exact same entities, and use the same JSON structure on the wire - so if you know what the REST API is doing and what the Entites are - you can easily port things around between languages. Helps to know Python first though!
You mentioned you want to download stuff - that will require the use of the Storage SDKs for python. Media Services just uses Azure Storage accounts. Meaning you can access the containers using SAS URl's to upload and download stuff. Look at the Storage samples for Python to see what to do there. https://pypi.org/project/azure-storage-blob/
The uploaded video are stored as an Assest file if the files are uploaded using Azure Media Services SDK. which will make it easier to stream video to different devices.
To stream or download an asset, you first need to "publish" it by creating a locator. Locators provide access to files contained in the asset.
Media Services supports two types of locators:
OnDemandOrigin locators, used to stream media (for example, MPEG DASH, HLS, or Smooth Streaming)
Access Signature (SAS) locators, used to download media files.
Once you create the locators, you can build the URLs that are used to stream or download your files.
Here's a guide for doing that using Rest API : https://learn.microsoft.com/en-us/azure/media-services/previous/media-services-rest-get-started
Note : you're uploading your videos directly to Azure Storage? If that's the case, instead of uploading your videos directly to Azure Storage, my suggestion would be to upload your videos using the Azure Media Services SDK
Azure Media Services has pretty good documentation which might help with your other asks: http://azure.microsoft.com/en-us/develop/media-services/resources/

Make the Google python client library for accessing Google cloud storage hit a stubbed API

I am writing an application that uses Google's python client for GCS.
https://cloud.google.com/storage/docs/reference/libraries#client-libraries-install-python
I've had no issues using this, until I needed to write my functional tests.
The way our organization tests integrations like this is to write a simple stub of the API endpoints I hit, and point the Google client library (in this case) to my stub, instead of needing to hit Google's live endpoints.
I'm using a service account for authentication and am able to point the client at my stub when fetching a token because it gets that value from the service account's json key that you get when you create the service account.
What I don't seem able to do is point the client library at my stubbed API instead of making calls directly to Google.
Some work arounds that I've though of, that I don't like are:
- Allow the tests to hit the live endpoints.
- Put in some configuration that toggles using the real Google client library, or a mocked version of the library. I'd rather mock the API versus having mock code deployed to production.
Any help with this is greatly appreciated.
I’ve made some research and it seems like there’s nothing supported specifically for Cloud Storage using python. I found this GitHub issue entry with a related discussion, but for go.
I think you can open a public issue tracker asking for this functionality. I’m afraid by now it’s easier to keep using your second workaround.

Trying to send data to Google Analytics with Measurement Protocol

So, I'm trying to send data to GA using their Measurement Protocol with Python. From what I can gather, I will be sending POST requests via HTTP, but I'm not sure where to start. The data will likely be coming from an API or Database.
My project is inspired by this video if it gives you a better idea: http://www.elisa-dbi.co.uk/blog/tracking-wemo-switch-motion-google-universal-analytics/
I guess I'm creating a wrapper, but I'm unclear to what exactly that is. Any advice or input would be greatly appreciated.
Thanks!
You can go throught the following documentation to send HTTP POST requests to google analytics
https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
By now you have probably already created your wrapper, but for what its worth, my firm has recently released a library under BSD license, with an API similar to that of Google's analytics.js.
https://github.com/analytics-pros/universal-analytics-python

Is it possible to use GCM with a python GAE backend?

I have a python GAE service, and I want to push notifications from the server to devices. The tutorial available for GCM is written for Java, and runs on ant+Tomcat/Jetty+JAE. I was under the impression that GCM would be a language-agnostic web service, and that I would be able to send push notifications regarding of my server-side platform.
Was I mistaken about GCM being compatible with my python GAE
backend?
If I CAN use it with my existing server, what instructions
can I follow (or adapt) to get started with sending notifications to
a mobile client?
Sure you can. GCM has a JSON REST API that you can work against. First you need to register you project here: http://developer.android.com/google/gcm/gs.html.
You basically do this:
Acquire you API key from http://developer.android.com/google/gcm/gs.html#access-key
Construct your payload, a dict containing registration_ids, data etc
Using url.fetch https://developers.google.com/appengine/docs/python/urlfetch/ to send the data as a JSON string to the GCM API
Here's another question with some code. Google Cloud Messaging HTTP Error 400: Bad Request and a blogpost (in not english, i think spanish. but there some sample code) http://pforray.wordpress.com/2012/07/05/ejemplo-gcm-en-appengine-python/
Use gcm-client
pip install gcm-client
Reference:
https://pypi.python.org/pypi/gcm-client/
Here you can find a module for Python interface for sending push notifications via Pushwoosh.
https://github.com/dbtsai/python-pushwoosh
You can use it for sending messages via Pushwoosh (it's free) or adapt it for your needs.

Categories