-
Notifications
You must be signed in to change notification settings - Fork 152
feat: update python SDK #3535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: update python SDK #3535
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| src/**/* linguist-generated=true | ||
| openmeter/**/* linguist-generated=true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,19 @@ | ||
| # python | ||
| .python-version | ||
| # Packaging | ||
| *.egg-info/ | ||
| *.egg | ||
| *.eggs/ | ||
| dist/ | ||
| build/ | ||
| CHANGELOG.md | ||
|
|
||
| # Python cache | ||
| __pycache__/ | ||
| *.pyc | ||
| build | ||
| dist | ||
| pydo.egg-info | ||
| .venv | ||
| *.pyo | ||
| *.pyd | ||
|
|
||
| # generate | ||
| openapi.yaml | ||
| # Virtual envs | ||
| .python-version | ||
| .venv/ | ||
| venv/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| include *.md | ||
| include LICENSE | ||
| include openmeter/py.typed | ||
| recursive-include tests *.py | ||
| recursive-include samples *.py *.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Examples | ||
|
|
||
| Install dependencies | ||
|
|
||
| ```sh | ||
| poetry install | ||
| ``` | ||
|
|
||
| Run examples | ||
|
|
||
| ```sh | ||
| OPENMETER_ENDPOINT=https://openmeter.cloud \ | ||
| OPENMETER_TOKEN=om_xxx \ | ||
| poetry run python ./sync/ingest.py | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| from os import environ | ||
| from typing import Optional | ||
| import asyncio | ||
|
|
||
| from openmeter.aio import Client | ||
| from openmeter.models import ( | ||
| CustomerCreate, | ||
| CustomerReplaceUpdate, | ||
| CustomerUsageAttribution, | ||
| ) | ||
| from corehttp.exceptions import HttpResponseError | ||
|
|
||
| ENDPOINT: str = environ.get("OPENMETER_ENDPOINT") or "https://openmeter.cloud" | ||
| token: Optional[str] = environ.get("OPENMETER_TOKEN") | ||
| customer_key: str = environ.get("OPENMETER_CUSTOMER_KEY") or "acme-corp-1" | ||
| subject_key: str = environ.get("OPENMETER_SUBJECT_KEY") or "acme-user-1" | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| async with Client( | ||
| endpoint=ENDPOINT, | ||
| token=token, | ||
| ) as client: | ||
| try: | ||
| # Create a customer | ||
| customer_create = CustomerCreate( | ||
| name="Acme Corporation", | ||
| key=customer_key, | ||
| description="A demo customer for testing", | ||
| primary_email="contact@acme-corp.example.com", | ||
| currency="EUR", | ||
| usage_attribution=CustomerUsageAttribution(subject_keys=[subject_key]), | ||
| metadata={ | ||
| "industry": "technology", | ||
| }, | ||
| ) | ||
|
|
||
| created_customer = await client.customer.customers.create(customer_create) | ||
| print(f"Customer created successfully with ID: {created_customer.id}") | ||
| print(f"Customer name: {created_customer.name}") | ||
| print(f"Customer key: {created_customer.key}") | ||
|
|
||
| # Get the customer by ID or key | ||
| customer = await client.customer.customers.get(created_customer.id) | ||
| print(f"\nRetrieved customer: {customer.name}") | ||
| print(f"Primary email: {customer.primary_email}") | ||
| print(f"Currency: {customer.currency}") | ||
|
|
||
| # Update the customer | ||
| customer_update = CustomerReplaceUpdate( | ||
| name="Acme Corporation Ltd.", | ||
| key=customer_key, | ||
| description="Updated demo customer", | ||
| primary_email="info@acme-corp.example.com", | ||
| currency="USD", | ||
| usage_attribution=CustomerUsageAttribution(subject_keys=[subject_key]), | ||
| metadata={ | ||
| "industry": "technology", | ||
| }, | ||
| ) | ||
|
|
||
| updated_customer = await client.customer.customers.update(created_customer.id, customer_update) | ||
| print(f"\nCustomer updated successfully") | ||
| print(f"Updated name: {updated_customer.name}") | ||
| print(f"Updated email: {updated_customer.primary_email}") | ||
| print(f"Updated currency: {updated_customer.currency}") | ||
|
|
||
| except HttpResponseError as e: | ||
| print(f"Error: {e}") | ||
|
|
||
|
|
||
| asyncio.run(main()) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify that referenced paths and packaging approach are correct.
The MANIFEST.in configuration includes several path dependencies that should be verified:
openmeter/py.typed— Ensure this PEP 561 marker file exists at the specified path for type hint support.🏁 Script executed:
Length of output: 287
🏁 Script executed:
Length of output: 984
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 1142
🏁 Script executed:
Length of output: 80
🏁 Script executed:
Length of output: 224
🏁 Script executed:
Length of output: 112
🏁 Script executed:
Length of output: 325
🏁 Script executed:
Length of output: 110
🏁 Script executed:
Length of output: 593
🏁 Script executed:
Length of output: 38
🏁 Script executed:
Length of output: 902
🏁 Script executed:
Length of output: 75
🏁 Script executed:
Length of output: 227
🏁 Script executed:
Length of output: 321
🏁 Script executed:
Length of output: 128
Fix MANIFEST.in: Remove non-existent directory references and correct LICENSE path.
The file references several paths that do not exist in the codebase:
include LICENSE: The LICENSE file is at repository root (./LICENSE), not in the package directory. Change toinclude ../LICENSEor remove if Poetry metadata already handles licensing.recursive-include tests *.pyandrecursive-include samples *.py *.md: Thetests/andsamples/directories do not exist. Remove these lines to prevent packaging errors.examples/directory exists with sample code but is not included; verify if this is intentional.Lines 1 and 3 are correct.
🤖 Prompt for AI Agents