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.
Project description
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
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.
Installation
The library is still in development, but you can already install it using pip:
pip install alpha-python
If you want to use the alpha cli for generating API code, you can install it using pip as well:
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:
# 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
alpha api gen --spec-file specification/openapi.yaml --service-package my_app
alpha api run --port 8080
2) Authenticate with Keycloak (OIDC)
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
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
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!
License
This library is licensed under the MIT License. See the LICENSE file for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file alpha_python-0.7.0.tar.gz.
File metadata
- Download URL: alpha_python-0.7.0.tar.gz
- Upload date:
- Size: 119.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e511fd5496d23bda124602d05e0c18eff888a90af9d736ccdd17acfaf918a6e
|
|
| MD5 |
875446253486d1639f46f90fe3c5721d
|
|
| BLAKE2b-256 |
e9250512a6343a7cb704ef34be81064fc755b58256098157fa62f7deef28df12
|
Provenance
The following attestation bundles were made for alpha_python-0.7.0.tar.gz:
Publisher:
python-publish.yml on BReijling/alpha
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alpha_python-0.7.0.tar.gz -
Subject digest:
5e511fd5496d23bda124602d05e0c18eff888a90af9d736ccdd17acfaf918a6e - Sigstore transparency entry: 1739758100
- Sigstore integration time:
-
Permalink:
BReijling/alpha@e4d6372abe05944e6daf49ad6159d81db272810c -
Branch / Tag:
refs/tags/0.7.0 - Owner: https://github.com/BReijling
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e4d6372abe05944e6daf49ad6159d81db272810c -
Trigger Event:
release
-
Statement type:
File details
Details for the file alpha_python-0.7.0-py3-none-any.whl.
File metadata
- Download URL: alpha_python-0.7.0-py3-none-any.whl
- Upload date:
- Size: 160.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a1e962633dc6c98bbaca7861d2060f5600c4687f0dc698ef146740d84b33ebd
|
|
| MD5 |
f89a95441c1fd209209876dd9121d345
|
|
| BLAKE2b-256 |
3bd78d198541a8779184699033f15edbc6c768115014dcbbdd7f7c910c8ab087
|
Provenance
The following attestation bundles were made for alpha_python-0.7.0-py3-none-any.whl:
Publisher:
python-publish.yml on BReijling/alpha
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alpha_python-0.7.0-py3-none-any.whl -
Subject digest:
7a1e962633dc6c98bbaca7861d2060f5600c4687f0dc698ef146740d84b33ebd - Sigstore transparency entry: 1739758104
- Sigstore integration time:
-
Permalink:
BReijling/alpha@e4d6372abe05944e6daf49ad6159d81db272810c -
Branch / Tag:
refs/tags/0.7.0 - Owner: https://github.com/BReijling
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@e4d6372abe05944e6daf49ad6159d81db272810c -
Trigger Event:
release
-
Statement type: