Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/milisp/daner
fastapi async command line manage (eg. create superuser -u username)
https://github.com/milisp/daner
fastapi fastapi-manage python3
Last synced: about 1 hour ago
JSON representation
fastapi async command line manage (eg. create superuser -u username)
- Host: GitHub
- URL: https://github.com/milisp/daner
- Owner: milisp
- License: other
- Created: 2022-08-16T08:59:24.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-18T03:35:12.000Z (over 2 years ago)
- Last Synced: 2024-12-22T17:45:44.439Z (about 1 month ago)
- Topics: fastapi, fastapi-manage, python3
- Language: Python
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# daner
[Github-flavored Markdown](https://guides.github.com/features/mastering-markdown/)
## install
```bash
pip install daner
```## example
### simple usage
```python
from daner import dong# command
# python manage.py hi --name milisp
@dong()
async def hi(name: str):
print(name)# command
# python manage.py hi -u milisp
# alias u=username
@dong(alias={"u": "username"})
async def create(username: str):
print(username)# command
# python manage.py greet --name milisp
# if you want to run a sync function
@dong(sync=True)
def greet(name):
print(name)
```### create superuser
```python
# manage.py
# createsuperuser
# $ python manage.py createsuperuser -u username -e email
from daner import dong
import databases
import getpass
import ormar
import sqlalchemy
import uvicornDB_URI = "sqlite:///fast.db"
database = databases.Database(DB_URI)
engine = sqlalchemy.create_engine(DB_URI)
metadata = sqlalchemy.MetaData()
metadata.create_all(engine)class User(ormar.Model):
class Meta(ormar.ModelMeta):
metadata = metadata
database = databaseid = ormar.Integer(primary_key=True)
username = ormar.String(max_length=60, unique=True)
password = ormar.String(max_length=2048)
email = ormar.String(max_length=80, nullable=True, unique=True)@dong(alias={"u": "username", "e": "email"})
async def createsuperuser(username: str, email: str = None):
await database.connect()
password = getpass.getpass("password: ")
password = "hashed" + password
await User(
username=username,
password=password,
email=email,
is_superuser=True,
).save()
await database.disconnect()```