Skip to main content

A Python client for the Malloy Publisher API

Project description

Malloy Publisher Client

A Python client for interacting with the Malloy Publisher API. This client provides a type-safe interface for working with Malloy projects, packages, models, and executing queries.

Features

  • Type-safe API client with Pydantic models
  • Full support for Malloy Publisher API endpoints
  • Async HTTP client using httpx
  • Comprehensive error handling
  • Context manager support for resource cleanup

Requirements

  • Python 3.11 or higher
  • UV package manager

Installation

You can install the package directly from PyPI:

pip install malloy-publisher-client
# or using uv
uv pip install malloy-publisher-client

For development installation:

  1. Clone the repository:
git clone https://github.com/yourusername/malloy-publisher-client.git
cd malloy-publisher-client
  1. Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate  # On Unix/macOS
# or
.venv\Scripts\activate  # On Windows
  1. Install dependencies using UV:
uv pip install -e ".[dev]"

Usage

Here's a basic example of how to use the client:

from malloy_publisher_client import MalloyAPIClient, QueryParams

# Initialize the client
client = MalloyAPIClient(
    base_url="https://your-malloy-publisher-url",
    api_key="your-api-key"  # Optional
)

# List all projects
projects = client.list_projects()

# List packages in a project
packages = client.list_packages("project_name")

# List models in a package
models = client.list_models("project_name", "package_name")

# Execute a query
query_params = QueryParams(
    project_name="project_name",
    package_name="package_name",
    path="model_path",
    query="your query here"
)
result = client.execute_query(query_params)

# Use as a context manager
with MalloyAPIClient(base_url="https://your-malloy-publisher-url") as client:
    # Your code here
    pass

Development

Setting Up Development Environment

  1. Install development dependencies:
uv pip install -e ".[dev]"
  1. Install pre-commit hooks (if configured):
pre-commit install

Code Style

This project uses:

  • Black for code formatting
  • MyPy for type checking
  • Ruff for linting

To format code:

black .

To run type checks:

mypy .

To run linter:

ruff check .

Running Tests

The project uses pytest for testing. To run tests:

pytest

For verbose output:

pytest -v

Building and Publishing

To build the package:

# Clean previous builds
rm -rf dist/ build/ *.egg-info/

# Install build tools
uv pip install build twine

# Build the package
python -m build

To publish to PyPI:

  1. Ensure you have a PyPI account and your credentials are configured in ~/.pypirc
  2. Build the package as described above
  3. Upload to PyPI:
python -m twine upload dist/*
  1. Create a git tag for the release:
git tag -a vX.Y.Z -m "Release vX.Y.Z"
git push origin vX.Y.Z

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests and ensure all checks pass
  5. Commit your changes using conventional commits
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Development Guidelines

  • Follow PEP 8 style guide
  • Add type hints to all functions
  • Write docstrings for all public functions and classes
  • Add tests for new functionality
  • Update documentation as needed

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

malloy_publisher_client-0.1.1.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

malloy_publisher_client-0.1.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file malloy_publisher_client-0.1.1.tar.gz.

File metadata

  • Download URL: malloy_publisher_client-0.1.1.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for malloy_publisher_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a57d5fb3999b4512e434f729b3ea272aeef5ceda3c51668d1c53a6085fbda8ad
MD5 806c93b0c6c81a79baf8ebad5e1356ce
BLAKE2b-256 132b7f0f3ffa531e11fa735d6c8cdad7b833f4fe5e008c2d37d57d8d836cb7c5

See more details on using hashes here.

File details

Details for the file malloy_publisher_client-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for malloy_publisher_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c178617e7bd20ed8d8197912c2ea4420f6fe7784d0055d5174a9f5d72e4d1d81
MD5 b02d21ab35044a8ba7ee6328ce4d22b2
BLAKE2b-256 e9bb2436d9262dbbad2f4d551d5a4af0b1cdcfbeb36017bb63c0fd4c2342a1ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page