Skip to content

Enchan1207/python-dsn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-dsn

Overview

DSN(Data Source Name) utility for python.

Installation

pip install git+https://github.com/Enchan1207/python-dsn

For setup.cfg:

install_requires=
    dsn @ git+https://github.com/Enchan1207/python-dsn

Usage

from dsn import DSN, DSNExpresser

# instantiate DSN from __init__
sample_dsn_full = DSN("https", "user", "password", "example.com", 443, "/path/to/source")
sample_dsn_simple = DSN("https", None, None, "example.com", 443, "/path/to/source")

# difference of URL representation and string representation
print("sample_dsn_full")
print(f"    string repr: {sample_dsn_full}")
print(f"    url    repr: {DSNExpresser.urlexpr(sample_dsn_full)}")

print("----")

print("sample_dsn_simple")
print(f"    string repr: {sample_dsn_simple}")
print(f"    url    repr: {DSNExpresser.urlexpr(sample_dsn_simple)}")

# instantiate DSN Object from string
url_str = "http://user:password@example.com:80/path/to/source/"
url_dsn = DSN.parsefrom(url_str)
assert(url_dsn is not None)

mysql_str = "mysql://user:pass@localhost:3306/test_database"
mysql_dsn = DSN.parsefrom(mysql_str)
assert(mysql_dsn is not None)

print(DSNExpresser.urlexpr(url_dsn))
print(DSNExpresser.urlexpr(mysql_dsn))

License

This repository is published under MIT License.