Skip to main content

sqlalchemy GUID

This is a simple extension to SQLAlchemy that adds support for UUID with postgresql compatibility to other database dialects.

Installation

pip install sqlalchemy_guid

Usage

Basically, you just need to import the GUID type and use it in your models:

    import uuid
    from sqlalchemy.ext.declarative import declarative_base
    from sqlalchemy import Column, Integer
    from sqlalchemy_guid import GUID

    Base = declarative_base()

    class User(Base):
        __tablename__ = 'users'
        id = Column(Integer, primary_key=True)
        guid = Column(GUID, default=uuid.uuid4)

For postgresql it will use the native uuid type, for other database dialects it will use a CHAR(32), storing as stringified hex values.

Now, when you create a new user, the guid will be automatically generated:

    user = User()
    session.add(user)
    session.commit()
    print(user.guid)

It will also work with other database dialects, such as sqlite:

    from sqlalchemy import create_engine
    engine = create_engine('sqlite:///:memory:')
    Base.metadata.create_all(engine)

    session = Session(engine)
    user = User()
    session.add(user)
    session.commit()
    print(user.guid)

More sqlite examples can be found in the tests.

License

MIT

Metadata

Release files for sqlalchemy-guid 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlalchemy-guid 1.0.2
File Size Uploaded Provenance Actions
sqlalchemy_guid-1.0.2.tar.gz 2.7 kB Without provenance Details for sqlalchemy_guid-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sqlalchemy-guid 1.0.2
File Interpreter ABI Platform Actions
sqlalchemy_guid-1.0.2-py3-none-any.whl Python 3 none any Details for sqlalchemy_guid-1.0.2-py3-none-any.whl

Total release size: 6.1 kB

Release files / sqlalchemy_guid-1.0.2.tar.gz

Download URL sqlalchemy_guid-1.0.2.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4e9bd0601784e32482b37875ef647c97aaaabbbfe0d78699f10a18d9038a8b77
BLAKE2b-256 checksum
How to use checksums
097e655081ec635d6bec4e155793e7b216548fd580bbc511f3df45d5c41e71f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.11.3 Darwin/22.4.0

Release files / sqlalchemy_guid-1.0.2-py3-none-any.whl

Download URL sqlalchemy_guid-1.0.2-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fab74417854ec82e0d8902dc0446350ca9c15f16444354db58da69835356be5d
BLAKE2b-256 checksum
How to use checksums
acd2d2a4ead34b8eb01062e3f047953ebc607991cf5bf5719bf4e4852263afa2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.11.3 Darwin/22.4.0

Security for sqlalchemy-guid 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page