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
import importlib | |
import pkgutil | |
def get_public_objects(package_name, parent_module=""): | |
objects = [] | |
full_package_name = ( | |
parent_module + "." + package_name if parent_module else package_name | |
) | |
package = importlib.import_module(full_package_name) |
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
from typing import Type, Callable, Any | |
from bson.objectid import ObjectId, InvalidId | |
from pydantic import BaseModel, ValidationError | |
from pydantic_core import CoreSchema, core_schema | |
class PydanticObjectId(ObjectId): | |
@classmethod | |
def __get_pydantic_core_schema__( |
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
from typing import Any, Collection, List, TypeVar, Annotated | |
from annotated_types import MinLen | |
from pydantic import BaseModel | |
_CollectionT = TypeVar("_CollectionT", bound=Collection[Any]) | |
NonEmpty = Annotated[_CollectionT, MinLen(1)] | |
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
from pydantic import BaseModel | |
BaseModel.model_config['protected_namespaces'] = () | |
class Potato(BaseModel): | |
model_potato: str | |
class Carrot(BaseModel): | |
model_carrot: str |
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
def a(n: int) -> int: | |
records = 0 | |
for _ in range(n): | |
for _ in range(n): | |
for _ in range(n): | |
records += 1 | |
return records | |
def sum_a(n: int) -> int: |
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
from fastapi import FastAPI | |
import httpx | |
from typer import Typer, Context | |
app = FastAPI() | |
@app.get("/") | |
def read_root(): | |
return {"Hello": "World"} |
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
from mcp.server import FastMCP | |
import logfire | |
import uvicorn | |
logfire.configure() | |
server = FastMCP("Summarizer") | |
app = server.sse_app() | |
logfire.instrument_starlette(app) |
OlderNewer