[英]Python: Where to place the config file in an API
I am working on an API, I just want to know what is the best place for config file which the user will provide for api to work.我正在开发一个 API,我只想知道用户将为 api 提供工作的配置文件的最佳位置是什么。 Basically I am working on getting tweets and I want the user to provide configurations(API credentials)
基本上我正在获取推文,我希望用户提供配置(API 凭据)
A common location for config files is in a folder in the User's home directory;配置文件的常见位置是在用户主目录中的文件夹中; eg
~/.config/my_api_config.cfg
, or ~/.my_api/config.cfg
etc...例如
~/.config/my_api_config.cfg
,或~/.my_api/config.cfg
等...
There is nothing stopping you from requiring the user to put the file in a very specific location eg, /must/be/this/exact/folder/config.cfg
没有什么可以阻止您要求用户将文件放在非常特定的位置,例如
/must/be/this/exact/folder/config.cfg
Often time programs will search a few places to see if a config file exists, eg,通常,程序会搜索几个地方以查看配置文件是否存在,例如,
same/directory/as/script/using/api/my_api_config.cfg
(per script config) same/directory/as/script/using/api/my_api_config.cfg
(每个脚本配置)~/.config/my_api_config.cfg
(per user config; could be anywhere else in specified user directory) ~/.config/my_api_config.cfg
(每个用户配置;可以在指定用户目录中的任何其他位置)/etc/my_api/config.cfg
(system-wide config) /etc/my_api/config.cfg
(系统范围的配置)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.