Skip to content

Improve public API surface and top-level exports #94

@ajshedivy

Description

@ajshedivy

Summary

Key classes that users need regularly are not exported from the top-level package, forcing users to know internal module paths. Additionally, the library lacks common Python conventions like environment variable configuration and a __version__ attribute.

Current Problems

1. Missing top-level exports

mapepire_python/__init__.py currently exports:

__all__ = [
    "apilevel", "threadsafety", "paramstyle",
    "DatabaseError", "DataError", "Error", "InterfaceError",
    "InternalError", "NotSupportedError", "OperationalError",
    "ProgrammingError", "IntegrityError", "Warning",
    "CONNECTION_CLOSED", "convert_runtime_errors",
    "connect", "Connection", "Cursor",
]

Missing exports that users need:

  • DaemonServer — the primary credentials class (users must do from mapepire_python.data_types import DaemonServer)
  • SQLJob — the core sync client (from mapepire_python.client.sql_job import SQLJob)
  • PoolJob — the core async client (from mapepire_python.pool.pool_job import PoolJob)
  • Pool, PoolOptions — connection pooling (from mapepire_python.pool.pool_client import Pool)
  • QueryOptions — query configuration
  • QueryState, JobStatus — useful enums for checking state
  • QueryResult — the result type users work with

2. No __version__ attribute

Version is defined in version.py but not re-exported:

# Users expect this to work:
import mapepire_python
print(mapepire_python.__version__)  # AttributeError

3. No environment variable configuration

Most Python database clients support environment variables for connection configuration (psycopg2, asyncpg, etc.). mapepire-python requires explicit credentials in every call.

Proposed environment variables:

  • MAPEPIRE_HOST — server hostname
  • MAPEPIRE_PORT — server port (default: 8076)
  • MAPEPIRE_USER — database user
  • MAPEPIRE_PASSWORD — database password
  • MAPEPIRE_CA_PATH — path to CA certificate file

This enables:

# With env vars set, just:
with connect() as conn:
    result = conn.execute("SELECT ...").fetchone()

4. No async connect() at the top level

The async connection requires a separate import:

from mapepire_python.asyncio.connection import connect  # Not discoverable

Should be accessible as:

from mapepire_python import async_connect
# or
from mapepire_python.asyncio import connect

Proposed Changes

  1. Add missing classes to __init__.py __all__:

    • DaemonServer, SQLJob, PoolJob, Pool, PoolOptions
    • QueryOptions, QueryResult, QueryState, JobStatus
  2. Add __version__ re-exported from version.py

  3. Add environment variable support to DaemonServer or connect():

    • Fall back to env vars when parameters are not provided
    • Document the supported env var names
  4. Add async_connect to top-level exports or document the async import path clearly

Files to Modify

  • mapepire_python/__init__.py — Add exports, __version__, async_connect
  • mapepire_python/data_types.py — Add env var fallback to DaemonServer
  • mapepire_python/base_job.py — Support env var config in _parse_connection_input()

Acceptance Criteria

  • All commonly-used classes importable from mapepire_python directly
  • mapepire_python.__version__ returns the current version string
  • connect() works with no arguments when env vars are set
  • Async connect is accessible from a documented top-level path
  • Existing tests still pass
  • README updated with new import patterns and env var documentation

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions