Coder Social home page Coder Social logo

microsoft / kiota-abstractions-python Goto Github PK

View Code? Open in Web Editor NEW
10.0 18.0 6.0 616 KB

Abstractions library for Kiota generated Python clients

Home Page: https://aka.ms/kiota/docs

License: MIT License

Python 99.78% Makefile 0.22%
python kiota openapi

kiota-abstractions-python's Introduction

Microsoft Kiota Abstractions Library for Python

PyPI version CI Actions Status Downloads

The Microsoft Kiota abstractions library for Python is the python package defining the basic constructs Kiota projects need once an SDK has been generated from an OpenAPI definition.

A Kiota generated project will need a reference to the abstraction package to build and run.

Read more about Kiota here.

Using the Abstractions Library

In order to use this library, install the package by running:

pip install microsoft-kiota-abstractions

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft's Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

kiota-abstractions-python's People

Contributors

andreatp avatar andrueastman avatar baywet avatar dependabot[bot] avatar github-actions[bot] avatar jzyworonek avatar microsoft-github-operations[bot] avatar microsoftopensource avatar musale avatar samwelkanda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kiota-abstractions-python's Issues

uritemplate version incompatibilities

Noticed by installing a generated SDK in a project with more dependencies I get this error message:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behavior is the source of the following dependency conflicts.
google-api-python-client 1.12.11 requires uritemplate<4dev,>=3.0.0, but you have uritemplate 4.1.1 which is incompatible.
kfp 1.8.19 requires uritemplate<4,>=3.0.1, but you have uritemplate 4.1.1 which is incompatible.

Given the number of issues we are facing with uritemplate libraries across implementations, I'm wondering if it makes sense to roll our own for kiota to be more independent ... cc. @baywet

Guid uri template path/query parameter values should be normalized to string

the std uri template library does not handle guids, and wont because it's not a standard API across languages and they don't want to bring on additional dependencies.
We should normalize the value to string (no curlies) before we pass it to the uri template engine.
Originally reported:
std-uritemplate/std-uritemplate#140
microsoft/kiota#4335

Example implementation https://github.com/microsoft/kiota-abstractions-dotnet/blob/5a93d126e9ce30ae332e65f30df7b941e7d7c265/src/RequestInformation.cs#L123

0.8.0 dependency issue

Our python project to communicate with azure b2c broke today with the 0.8.0 release. If we revert back to 0.5.1 it works agin:

packages/kiota_abstractions/request_information.py", line 8, in <module>
    from opentelemetry import trace
ModuleNotFoundError: No module named 'opentelemetry'

HeadersCollection usability

As demonstrated in microsoft/kiota#3962 I think we are facing a usability regression.
I don't have a strong opinion on where to go from here but either:

  • an extra constructor
  • more methods overload, e.g.get_all that accepts also a plain Dict, or similar.

cc. @baywet

Getting error "The MIME type 'a, p, p, l, i, c, a, t, i, o, n, /, j, s, o, n' requires a '/' character between type and subtype, such as 'text/plain'."

Error: "The MIME type 'a, p, p, l, i, c, a, t, i, o, n, /, j, s, o, n' requires a '/' character between type and subtype, such as 'text/plain'."

...
from msgraph import GraphRequestAdapter
request_adapter = GraphRequestAdapter(auth_provider)

from msgraph import GraphServiceClient
client = GraphServiceClient(request_adapter)

import asyncio

async def get_user_messages():
    try:
        messages = await (client.users_by_id('USER_ID').messages.get())
        print('getting each message')
        for msg in messages.value:
            print(msg.subject, msg.id)
    except Exception as e:
        print(e.error.message)
print('getting messages')
asyncio.run(get_user_messages())

Workaround:
kiota_abstractions/request_information.py

...
 @property
    def request_headers(self) -> Optional[Dict]:
        final = {}
        for key, value in self.headers.items():
            print("value", value)
            print("type value", type(value))
            if 'application' in str(value):
                final[key] = str(value)
            else:
                final[key] = ', '.join(value)
        return final
...

base_bearer_token_authentication_provider.py failing with new version

Hello,

Our code has stopped working which updates b2c policies:

response = await self.app_client.trust_framework.policies.by_trust_framework_policy_id(
    id
).content.put(
    bytes(xml, encoding="utf8")
)

The error we now get is:

  File "/opt/homebrew/lib/python3.11/site-packages/msgraph/generated/trust_framework/policies/item/value/content_request_builder.py", line 78, in put
    return await self.request_adapter.send_primitive_async(request_info, "bytes", error_mapping)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/kiota_http/httpx_request_adapter.py", line 207, in send_primitive_async
    response = await self.get_http_response_message(request_info)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/kiota_http/httpx_request_adapter.py", line 324, in get_http_response_message
    await self._authentication_provider.authenticate_request(request_info)
  File "/opt/homebrew/lib/python3.11/site-packages/kiota_abstractions/authentication/base_bearer_token_authentication_provider.py", line 48, in authenticate_request
    token = await self.access_token_provider.get_authorization_token(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: AzureIdentityAccessTokenProvider.get_authorization_token() takes 2 positional arguments but 3 were given

Any ideas?

add shorthand functions for serialization

to facilitate serialization and deserialization of models and collections of models, we're adding static helper functions.
More details to be found at microsoft/kiota#3406

For serialization we need:

  • Serialize(contentType, model): string
  • Serialize(contentType, model): stream
  • SerializeCollection(contentType, models): string
  • SerializeCollection(contentType, models): stream
  • Serialize(model): stream (maps to same one passing the json content type as a constant)
  • Serialize(model): string (same)
  • Serialize(models): stream (same)
  • Serialize(models): string (same)

Note: if converting from stream to string is trivial we can ommit the string overloads
Note: if another parameter for the serialization method needs to be added, feel free to do so
Note: if both a string and and stream method need to be added, but can't have the same name, name the string methods with AsString suffix
Note: if the Json methods and the ones accepting the same content type can't have the same namde/would need to be aliased in the consuming code to avoid conflicts, as a ToJsonSuffix (full convention with string SerializeCollectionToJsonAsString)

For deserialization we need:

  • Deserialize(contentType, stream, createTFromDiscriminatorMethod): T
  • Deserialize(contentType, string, createTFromDiscriminatorMethod): T
  • Deserialize(contentType, stream): T (uses reflection, only if possible, calls into the previous one)
  • Deserialize(contentType, string): T (same)
  • DeserializeCollection(contentType, stream, createCallback): T[]
  • DeserializeCollection(contentType, string, createCallback): T[]
  • reflection version x2
  • Json equivalent with constant for all the previous

Note: the same notes as serialization apply
Note: if the collection and single methods can have the same name, make them same

[proposal] Consider consolidating kiota python libraries into a single repo

Currently, the various repos are using(or not) a variety of tools and different setup (at least I can count 2 separate styles) i.e.:

  • pipenv in kiota-http-python, kiota-serialization-json-python
  • plain global python installation in this repo and e.g. , kiota-serialization-text-python

Those different setups are causing some friction during development, where I always have to look up the CI setup to understand which command to use/where.
Also, the different setups, easily run out of sync.

There are various ways to tackle those issues i.e.:

  • use reusable GH Actions across the different repos -> this will force to have a consistent setup
  • have stronger checks and guidelines to contribute
  • [last but not least] consolidate in a single repo for the language

I'm (no surprise ๐Ÿ˜›) in favor of the latter solution and I propose switching to a language-specific monorepo (as we did for kiota-java).
Looking up on the internet I cannot find a "good story" for Python tools natively supporting multi-projects builds, but, still, with a little duplication we can have a viable setup as described here.
I do believe that this would be already an improvement with respect to the current setup, where we will share CI pipelines, documentation, contributing guidelines, and more.

Let me know your thoughts!

ValuError during lazy load if module already exist in sys.modules

Description

Lazy loading some modules fails with ValueError: module object for "module-name" substituted in sys.modules during a lazy load. This occurs if the module already exists in sys.modules.

To Do

Add a check in the lazy_import helper function to return if module already exists in sys.modules.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.