Skip to content

Commit

Permalink
Merge pull request #4 from memfault/willr/axiom_py_080_update
Browse files Browse the repository at this point in the history
Update to v0.8.0
  • Loading branch information
WRansohoff authored Oct 11, 2024
2 parents 45ca752 + 36946ee commit 7bfffa5
Show file tree
Hide file tree
Showing 44 changed files with 1,570 additions and 650 deletions.
58 changes: 25 additions & 33 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,16 @@ on:
tags:
- "v*"

env:
PYTHON_VERSION: "3.8"
POETRY_VERSION: "1.5"

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: chartboost/ruff-action@v1
- uses: chartboost/ruff-action@v1
with:
python-version: ${{ env.PYTHON_VERSION }}
- run: pip install poetry==${{ env.POETRY_VERSION }}
- run: poetry install
- run: poetry run black --check axiom tests examples
- run: poetry run pylint -E axiom tests examples
args: 'format --check'

test-integration:
name: Test Integration
Expand All @@ -36,33 +29,27 @@ jobs:
needs: lint
strategy:
fail-fast: true
max-parallel: 1
matrix:
python: ["3.8", "3.9", "3.10", "3.11"]
environment:
- development
- staging
include:
- environment: development
url: TESTING_DEV_API_URL
token: TESTING_DEV_TOKEN
org_id: TESTING_DEV_ORG_ID
- environment: staging
url: TESTING_STAGING_API_URL
token: TESTING_STAGING_TOKEN
org_id: TESTING_STAGING_ORG_ID
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- run: pip install poetry==${{ env.POETRY_VERSION }}
- run: poetry install
- run: poetry run python -m pytest
- name: Install uv
uses: astral-sh/setup-uv@v3
- name: Test against development
run: uv run pytest
env:
AXIOM_URL: ${{ secrets[matrix.url] }}
AXIOM_TOKEN: ${{ secrets[matrix.token] }}
AXIOM_ORG_ID: ${{ secrets[matrix.org_id] }}
AXIOM_URL: ${{ secrets.TESTING_DEV_API_URL }}
AXIOM_TOKEN: ${{ secrets.TESTING_DEV_TOKEN }}
AXIOM_ORG_ID: ${{ secrets.TESTING_DEV_ORG_ID }}
- name: Test against staging
run: uv run pytest
env:
AXIOM_URL: ${{ secrets.TESTING_STAGING_API_URL }}
AXIOM_TOKEN: ${{ secrets.TESTING_STAGING_TOKEN }}
AXIOM_ORG_ID: ${{ secrets.TESTING_STAGING_ORG_ID }}

publish:
name: Publish on PyPi
Expand All @@ -72,8 +59,13 @@ jobs:
- test-integration
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v3
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- run: pip install poetry==${{ env.POETRY_VERSION }}
- run: poetry publish --build -u __token__ -p "${{ secrets.PYPI_TOKEN }}"
python-version-file: "pyproject.toml"
- run: uv build
- run: uvx twine upload dist/*
env:
TWINE_USERNAME: "__token__"
TWINE_PASSWORD: "${{ secrets.PYPI_TOKEN }}"
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: local
hooks:
- id: ruff-check
name: ruff check --fix
entry: uv run ruff check --fix
language: system
types: [python]
- id: ruff-format
name: ruff format
entry: uv run ruff format
language: system
types: [python]
2 changes: 0 additions & 2 deletions .pylintrc

This file was deleted.

67 changes: 53 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,41 +49,80 @@ Otherwise create a personal token in [the Axiom settings](https://cloud.axiom.co
You can also configure the client using options passed to the client constructor:

```py
import axiom
import axiom_py

client = axiom.Client("<api token>", "<org id>")
client = axiom_py.Client("<api token>", "<org id>")
```

Create and use a client like this:

```py
import axiom
import axiom_py
import rfc3339
from datetime import datetime,timedelta

client = axiom.Client()

time = datetime.utcnow() - timedelta(hours=1)
time_formatted = rfc3339.format(time)
client = axiom_py.Client()

client.ingest_events(
dataset="my-dataset",
events=[
{"foo": "bar", "_time": time_formatted},
{"bar": "baz", "_time": time_formatted},
{"foo": "bar"},
{"bar": "baz"},
])
client.query(r"['my-dataset'] | where foo == 'bar' | limit 100")
```

for more examples, check out the [examples](examples) directory.
For more examples, see [`examples/client.py`](examples/client.py).

## Logger

You can use the `AxiomHandler` to send logs from the `logging` module to Axiom
like this:

```python
import axiom_py
from axiom_py.logging import AxiomHandler
import logging


def setup_logger():
client = axiom_py.Client()
handler = AxiomHandler(client, "my-dataset")
logging.getLogger().addHandler(handler)
```

For a full example, see [`examples/logger.py`](examples/logger.py).

If you use [structlog](https://github.com/hynek/structlog), you can set up the
`AxiomProcessor` like this:

```python
from axiom_py import Client
from axiom_py.structlog import AxiomProcessor


def setup_logger():
client = Client()

structlog.configure(
processors=[
# ...
structlog.processors.add_log_level,
structlog.processors.TimeStamper(fmt="iso", key="_time"),
AxiomProcessor(client, "my-dataset"),
# ...
]
)
```

For a full example, see [`examples/structlog.py`](examples/structlog.py).

## Contributing

This project uses [Poetry](https://python-poetry.org) for dependecy management
and packaging, so make sure that this is installed (see [Poetry Installation](https://python-poetry.org/docs/#installation)).
This project uses [uv](https://docs.astral.sh/uv) for dependency management
and packaging, so make sure that this is installed.

Run `poetry install` to install dependencies and `poetry shell` to activate a
virtual environment.
To lint and format files before commit, run `uvx pre-commit install`.

## License

Expand Down
10 changes: 0 additions & 10 deletions axiom/__init__.py

This file was deleted.

140 changes: 0 additions & 140 deletions axiom/datasets.py

This file was deleted.

5 changes: 0 additions & 5 deletions axiom/query/__init__.py

This file was deleted.

26 changes: 0 additions & 26 deletions axiom/users.py

This file was deleted.

Loading

0 comments on commit 7bfffa5

Please sign in to comment.