Metadata-Version: 2.4
Name: alpha-python
Version: 0.6.1
Summary: Alpha is intended to be the first dependency you need to add to your Python application. It is a Python library which contains standard building blocks that can be used in applications that are used as APIs and/or make use of database interaction.
Author-email: Bart Reijling <bart@reijling.eu>
License-Expression: MIT
Project-URL: Homepage, https://github.com/breijling/alpha
Project-URL: Issues, https://github.com/breijling/alpha/issues
Project-URL: Documentation, https://alpha-python.readthedocs.io/en/latest/
Project-URL: Changelog, https://alpha-python.readthedocs.io/en/latest/changelog/
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: <3.15,>=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: attrs>=25.4.0
Requires-Dist: gunicorn>=23.0.0
Requires-Dist: jsonpatch>=1.33
Requires-Dist: numpy>=2.3.5
Requires-Dist: pandas>=1.13
Requires-Dist: pydantic>=2.12.5
Requires-Dist: pyjwt>=2.10.1
Requires-Dist: six>=1.17.0
Requires-Dist: sqlalchemy>=2.0.44
Requires-Dist: requests>=2.28.1
Requires-Dist: dependency-injector[yaml]!=4.48.3,<5.0.0,>=4.42.0
Requires-Dist: argon2-cffi>=25.1.0
Requires-Dist: httpx
Requires-Dist: cryptography
Provides-Extra: api-generator
Requires-Dist: openapi-generator-cli==7.14.0; extra == "api-generator"
Requires-Dist: jdk4py; extra == "api-generator"
Provides-Extra: flask
Requires-Dist: connexion[swagger-ui]<3,>=2.14.2; extra == "flask"
Requires-Dist: swagger-ui-bundle>=0.0.2; extra == "flask"
Requires-Dist: python_dateutil>=2.6.0; extra == "flask"
Requires-Dist: itsdangerous==1.1.0; extra == "flask"
Requires-Dist: MarkupSafe<2.0.2; extra == "flask"
Requires-Dist: Jinja2==2.11.2; extra == "flask"
Requires-Dist: Flask<2,>=1.1.2; extra == "flask"
Requires-Dist: Werkzeug<2.1.0,>=1.0.1; extra == "flask"
Requires-Dist: flask-cors>=3.0.10; extra == "flask"
Requires-Dist: Flask-Compress>=1.13; extra == "flask"
Provides-Extra: mysql
Requires-Dist: pymysql>=1.1.2; extra == "mysql"
Provides-Extra: postgresql
Requires-Dist: psycopg2-binary>=2.9.11; extra == "postgresql"
Provides-Extra: ldap
Requires-Dist: ldap3>=2.9.1; extra == "ldap"
Dynamic: license-file

# Alpha

Alpha is intended to be the first dependency you need to add to your Python application. It is a Python library which contains standard building blocks that can be used in applications that are used as APIs and/or make use of database interaction.

## Badges

[![PyPI version](https://badge.fury.io/py/alpha-python.svg?icon=si%3Apython)](https://badge.fury.io/py/alpha-python)
[![PyPI Downloads](https://img.shields.io/pypi/dm/alpha-python.svg?label=PyPI%20downloads)](https://pypistats.org/packages/alpha-python)
[![Build Status](https://github.com/breijling/alpha/actions/workflows/python-app.yml/badge.svg?branch=main)](https://github.com/breijling/alpha/actions/workflows/python-app.yml)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/alpha-python.svg?color=%2334D058)](https://pypi.org/project/alpha-python)
[![Coverage Status](https://coveralls.io/repos/github/BReijling/alpha/badge.svg?branch=main)](https://coveralls.io/github/BReijling/alpha?branch=main)
[![uv](https://img.shields.io/badge/package%20manager-uv-5C4EE5)](https://docs.astral.sh/uv/)
[![mypy](https://img.shields.io/badge/type%20check-mypy-2A6DB2)](https://mypy-lang.org/)
[![Pytest](https://img.shields.io/badge/testing-pytest-0A9EDC)](https://docs.pytest.org/)
[![PEP8](https://img.shields.io/badge/code%20style-pep8-orange.svg)](https://www.python.org/dev/peps/pep-0008/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![Documentation Status](https://readthedocs.org/projects/alpha-python/badge/?version=latest)](https://alpha-python.readthedocs.io/en/latest/)
[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)
[![Sponsor](https://img.shields.io/badge/Sponsor-GitHub-pink?logo=github)](https://github.com/sponsors/BReijling)

## TL;DR

Alpha provides a comprehensive set of tools for building Python applications that interact with APIs and databases, including API code generation, authentication and authorization, database access layers, error handling, logging, and more. It is designed to be the first dependency you add to your project, providing a solid foundation for your application's architecture.

## Documentation

Full documentation is available at [alpha-python.readthedocs.io](https://alpha-python.readthedocs.io/).

## Installation

The library is still in development, but you can already install it using pip:

```shell
pip install alpha-python
```

If you want to use the alpha cli for generating API code, you can install it using pip as well:

```shell
pip install alpha-python[api-generator]
```

If you want to add the library to your API project, you can add it to your pyproject.toml file:

```shell
# Poetry example
poetry add alpha-python --extras "flask, postgresql"
poetry add --dev alpha-python --extras "api-generator"

# UV example
uv add alpha-python --extra flask --extra postgresql
uv add --dev alpha-python --extra api-generator
```

## Features

- API code generation
- Authentication and authorization
- Database interaction
- Logging
- Error handling
- And much more!

## Usage

The library contains many components. Below are a few practical examples that map to the guides in the documentation.

### 1) API code generation using OpenAPI spec

```shell
alpha api gen --spec-file specification/openapi.yaml --service-package my_app

alpha api run --port 8080
```

### 2) Authenticate with Keycloak (OIDC)

```python
from alpha import KeyCloakOIDCConnector, KeyCloakProvider, PasswordCredentials

keycloak_connector = KeyCloakOIDCConnector(
	base_url="https://keycloak.example.com",
	realm="myrealm",
	client_id="myclient",
	client_secret="myclientsecret",
)

keycloak_provider = KeyCloakProvider(connector=keycloak_connector)

credentials = PasswordCredentials(username="user1", password="user1_password")
identity = keycloak_provider.authenticate(credentials)
```

### 3) Query data using SqlAlchemyDatabase + SqlAlchemyRepository

```python
from alpha import SqlAlchemyDatabase, SqlAlchemyRepository
from my_app import User

db = SqlAlchemyDatabase(conn_str="postgresql://user:password@localhost:5432/mydatabase")

with db.get_session() as session:
	users = SqlAlchemyRepository[User](session=session, default_model=User)
	user = users.get_by_id(1)
```

### 4) Use Unit of Work for transactional operations

```python
from alpha import (
	RepositoryModel,
	SqlAlchemyDatabase,
	SqlAlchemyRepository,
	SqlAlchemyUnitOfWork,
)
from my_app import User, OrmMapper

db = SqlAlchemyDatabase(..., mapper=OrmMapper)
repositories = [
	RepositoryModel(
		name="users",
		repository=SqlAlchemyRepository[User],
		default_model=User,
	)
]

uow = SqlAlchemyUnitOfWork(db=db, repos=repositories)

with uow:
	user = uow.users.get_by_id(1)
```

See also:

- Design principles and patterns: https://alpha-python.readthedocs.io/en/latest/concepts/design-principles/
- Dependency injection concept: https://alpha-python.readthedocs.io/en/latest/concepts/dependency-injection/
- API code generation guide: https://alpha-python.readthedocs.io/en/latest/guides/api-generation/
- Authentication guide: https://alpha-python.readthedocs.io/en/latest/guides/authentication/
- Database interaction guide: https://alpha-python.readthedocs.io/en/latest/guides/database-interaction/

## Contributing

If you want to contribute to the development of this library, you can fork the repository and create a pull request with your changes.

## Support

If Alpha saves you time in production, consider supporting development by buying me a coffee! Your support helps me to continue improving the library and adding new features. Thank you!

<a href="https://www.buymeacoffee.com/breijling"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=breijling&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff" /></a>

## License

This library is licensed under the MIT License. See the LICENSE file for more information.
