Skip to content

Commit ec881c2

Browse files
authored
chore: add claude file (#1268)
1 parent 48544b9 commit ec881c2

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

.claude/settings.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(find:*)",
5+
"Bash(rg:*)",
6+
"Bash(grep:*)",
7+
"Bash(ls:*)",
8+
"Bash(cat:*)",
9+
"Bash(head:*)",
10+
"Bash(tail:*)"
11+
],
12+
"deny": []
13+
}
14+
}

CLAUDE.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is the Langfuse Python SDK, a client library for accessing the Langfuse observability platform. The SDK provides integration with OpenTelemetry (OTel) for tracing, automatic instrumentation for popular LLM frameworks (OpenAI, Langchain, etc.), and direct API access to Langfuse's features.
8+
9+
## Development Commands
10+
11+
### Setup
12+
```bash
13+
# Install Poetry plugins (one-time setup)
14+
poetry self add poetry-dotenv-plugin
15+
poetry self add poetry-bumpversion
16+
17+
# Install all dependencies including optional extras
18+
poetry install --all-extras
19+
20+
# Setup pre-commit hooks
21+
poetry run pre-commit install
22+
```
23+
24+
### Testing
25+
```bash
26+
# Run all tests with verbose output
27+
poetry run pytest -s -v --log-cli-level=INFO
28+
29+
# Run a specific test
30+
poetry run pytest -s -v --log-cli-level=INFO tests/test_core_sdk.py::test_flush
31+
32+
# Run tests in parallel (faster)
33+
poetry run pytest -s -v --log-cli-level=INFO -n auto
34+
```
35+
36+
### Code Quality
37+
```bash
38+
# Format code with Ruff
39+
poetry run ruff format .
40+
41+
# Run linting (development config)
42+
poetry run ruff check .
43+
44+
# Run type checking
45+
poetry run mypy .
46+
47+
# Run pre-commit hooks manually
48+
poetry run pre-commit run --all-files
49+
```
50+
51+
### Building and Releasing
52+
```bash
53+
# Build the package
54+
poetry build
55+
56+
# Run release script (handles versioning, building, tagging, and publishing)
57+
poetry run release
58+
59+
# Generate documentation
60+
poetry run pdoc -o docs/ --docformat google --logo "https://langfuse.com/langfuse_logo.svg" langfuse
61+
```
62+
63+
## Architecture
64+
65+
### Core Components
66+
67+
- **`langfuse/_client/`**: Main SDK implementation built on OpenTelemetry
68+
- `client.py`: Core Langfuse client with OTel integration
69+
- `span.py`: LangfuseSpan, LangfuseGeneration, LangfuseEvent classes
70+
- `observe.py`: Decorator for automatic instrumentation
71+
- `datasets.py`: Dataset management functionality
72+
73+
- **`langfuse/api/`**: Auto-generated Fern API client
74+
- Contains all API resources and types
75+
- Generated from OpenAPI spec - do not manually edit these files
76+
77+
- **`langfuse/_task_manager/`**: Background processing
78+
- Media upload handling and queue management
79+
- Score ingestion consumer
80+
81+
- **Integration modules**:
82+
- `langfuse/openai.py`: OpenAI instrumentation
83+
- `langfuse/langchain/`: Langchain integration via CallbackHandler
84+
85+
### Key Design Patterns
86+
87+
The SDK is built on OpenTelemetry for observability, using:
88+
- Spans for tracing LLM operations
89+
- Attributes for metadata (see `LangfuseOtelSpanAttributes`)
90+
- Resource management for efficient batching and flushing
91+
92+
The client follows an async-first design with automatic batching of events and background flushing to the Langfuse API.
93+
94+
## Configuration
95+
96+
Environment variables (defined in `_client/environment_variables.py`):
97+
- `LANGFUSE_PUBLIC_KEY` / `LANGFUSE_SECRET_KEY`: API credentials
98+
- `LANGFUSE_HOST`: API endpoint (defaults to https://cloud.langfuse.com)
99+
- `LANGFUSE_DEBUG`: Enable debug logging
100+
- `LANGFUSE_TRACING_ENABLED`: Enable/disable tracing
101+
- `LANGFUSE_SAMPLE_RATE`: Sampling rate for traces
102+
103+
## Testing Notes
104+
105+
- Create `.env` file based on `.env.template` for integration tests
106+
- E2E tests with external APIs (OpenAI, SERP) are typically skipped in CI
107+
- Remove `@pytest.mark.skip` decorators in test files to run external API tests
108+
- Tests use `respx` for HTTP mocking and `pytest-httpserver` for test servers
109+
110+
## Important Files
111+
112+
- `pyproject.toml`: Poetry configuration, dependencies, and tool settings
113+
- `ruff.toml`: Local development linting config (stricter)
114+
- `ci.ruff.toml`: CI linting config (more permissive)
115+
- `langfuse/version.py`: Version string (updated by release script)
116+
117+
## API Generation
118+
119+
The `langfuse/api/` directory is auto-generated from the Langfuse OpenAPI specification using Fern. To update:
120+
121+
1. Generate new SDK in main Langfuse repo
122+
2. Copy generated files from `generated/python` to `langfuse/api/`
123+
3. Run `poetry run ruff format .` to format the generated code
124+
125+
## Testing Guidelines
126+
127+
### Approach to Test Changes
128+
- Don't remove functionality from existing unit tests just to make tests pass. Only change the test, if underlying code changes warrant a test change.
129+
130+
## Python Code Rules
131+
132+
### Exception Handling
133+
- Exception must not use an f-string literal, assign to variable first

0 commit comments

Comments
 (0)