Skip to main content

a signing key extension for sqlalchemy

Project description

Signing logo

sqlalchemy_signing

License: BSD-3-Clause

Buy me a coffee

a signing key extension for sqlalchemy

About

The sqlalchemy_signing library is a useful tool for Python applications using sqlalchemy that require secure and robust management of signing keys. It grew out of the Flask-Signing project, which was more tightly coupled to the Flask framework. Do you need to generate single-use tokens for one-time actions like email verification or password reset? sqlalchemy_signing can handle that. Are you looking for a simple method for managing API keys? Look no further.

Installation

First, install the sqlalchemy_signing package. You can do this with pip:

pip install sqlalchemy_signing

Basic Usage

After you've installed the sqlalchemy_signing package, you can use it in your Flask application. Here's an example of how you might do this:

from sqlalchemy_signing import (
    Signatures,
    RateLimitExceeded
)

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'  # Use your actual database URI
app.secret_key = "Your_Key_Here"

with app.app_context():
    signatures = Signatures(app.config['SQLALCHEMY_DATABASE_URI'], byte_len=24)


@app.route('/sign')
def sign():
    key = signatures.write_key(scope='test', expiration=1, active=True, email='test@example.com')
    return f'Key generated: {key}'

@app.route('/verify/<key>')
def verify(key):
    try:
        valid = signatures.verify_key(signature=key, scope='test')
        return f'Key valid: {valid}'
    except RateLimitExceeded:
        return "Rate limit exceeded"

@app.route('/expire/<key>')
def expire(key):
    expired = signatures.expire_key(key)
    return f'Key expired: {expired}'
    
@app.route('/all')
def all():
    all = signatures.get_all()
    return f'Response: {all}'

In this basic example, a new signing key is generated and written to the database when you visit the /sign route, and the key is displayed on the page. Then, when you visit the /verify/<key> route (replace with the actual key), the validity of the key is checked and displayed. You can expire a key using the /expire/<key> route, and view all records with the /all route.

This is a rather basic example and your actual use of the sqlalchemy_signing package may be more complex depending on your needs. It's important to secure your signing keys and handle them appropriately according to your application's security requirements. Further usage examples can be found in the examples directory of the sqlalchemy_signing Github repository.

Developers

Contributions are welcome! You can read the developer docs at https://signebedi.github.io/sqlalchemy_signing. If you're interested, review (or add to) the feature ideas at https://github.com/signebedi/sqlalchemy_signing/issues.

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

sqlalchemy_signing-1.0.8.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

sqlalchemy_signing-1.0.8-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy_signing-1.0.8.tar.gz.

File metadata

  • Download URL: sqlalchemy_signing-1.0.8.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for sqlalchemy_signing-1.0.8.tar.gz
Algorithm Hash digest
SHA256 94d0c888c930513afd4e2cea6ccfb766e77e9dfaff04a736c88a554b56bab0b1
MD5 7a616a49a01419fbe4b7cb6292cf17ff
BLAKE2b-256 a1dc3280f017db25a10b08aba935d6a133973d97e0173c8ac457294d1935b638

See more details on using hashes here.

File details

Details for the file sqlalchemy_signing-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_signing-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 1209da27e0874ae8a6f9e50aa3358a734b8b49da505ae907e72de334c7bb6874
MD5 59c5b07c9ff1b4a4179bdae04cbe18a8
BLAKE2b-256 504cfa3f05bba9bd47b163b1951a66feb29019597ff1d9f68cd3a653c1e89c43

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