Environize enables environment and state savvy DataMigration tools for Django
- Decorators
adds a pair of decorators (only_in and except_in) for use with the migrations.RunPython method.
use django’s DataMigrations to allow dev data and prod data to be different.
exclude large data creation migrations from tests which may define their own data.
- Command(s)
adds a loaddata method that loads JSON fixtures into the database based on the state of the migration.
different from ./manage.py loaddata or call_command("loaddata"), which both load fixtures to the database based on the current state of models.
no more updating fixtures to keep them current. The data model in the fixture is tied to the state of your models in the migration.
Decorators - Usage
Exclude Tests
from django.db import migrations
import environize
# runs in every env except testing
@environize.except_in(envs=["test"])
def except_test_data(apps, schema_editor):
Ham = apps.get_model("app", "Ham")
Ham.objects.create(name="not-test")
@environize.except_in(envs=["test"])
def remove_hams(apps, schema_editor):
Ham = apps.get_model("app", "Ham")
Ham.objects.all().delete()
class Migration(migrations.Migration):
dependencies = [
('app', '0002_auto_20180916_1122'),
]
operations = [
migrations.RunPython(except_test_data, remove_hams)
]
Production Only Data
from django.db import migrations
import environize
# runs in every env except testing
@environize.only_in(envs=["production"])
def add_prod_data(apps, schema_editor):
Ham = apps.get_model("app", "Ham")
Ham.objects.create(name="not-test")
@environize.only_in(envs=["production"])
def remove_hams(apps, schema_editor):
Ham = apps.get_model("app", "Ham")
Ham.objects.all().delete()
class Migration(migrations.Migration):
dependencies = [
('app', '0002_auto_20180916_1122'),
]
operations = [
migrations.RunPython(add_prod_data, remove_hams)
]
Commands - Usage
import os
from django.db import migrations
import environize
PATH = 'path/to/fixtures/'
def load_fixture(apps, schema_editor):
fixture_file = os.path.join(PATH, 'myfixture.json')
environize.loaddata(apps, fixture_file)
class Migration(migrations.Migration):
dependencies = [
('app', '0003_auto_20180916_1122'),
]
operations = [
migrations.RunPython(load_fixture, lambda x, y: None)
]
Feature Support
- Environize officially supports:
Python 2.7 on Django 1.11 LTS
Python 3.5+ on Django 2+
Installation
To install Environize, use pipenv (or pip, of course):
$ pipenv install environize
Inside various settings files set an ENVIRONMENT variable.
# /settings_production.py
ENVIRONMENT = 'production'
# /settings_qa.py
ENVIRONMENT = 'qa'
# /settings_dev.py
ENVIRONMENT = 'dev'
The default env keys are listed below but can be overridden by setting ENVIRONIZE_ENVS in your django settings:
# these are the default env keys
ENVIRONIZE_ENVS = ("dev", "test", "ci", "qa", "staging", "production")
# by default this key will be used if one is not set in a settings file.
DEFAULT_ENV = "dev"
Documentation
TBD
How to Contribute
Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
Fork the repository on GitHub to start making your changes to the master branch (or branch off of it).
Write a test which shows that the bug was fixed or that the feature works as expected.
Send a pull request. Make sure to add yourself to AUTHORS.
Metadata
Release files for environize 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| environize-0.0.1.tar.gz | 7.7 kB | Without provenance | Details for environize-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| environize-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for environize-0.0.1-py3-none-any.whl |
Total release size: 18.1 kB
Release files / environize-0.0.1.tar.gz
| Download URL | environize-0.0.1.tar.gz |
|---|---|
| Size | 7.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e2f1f55f245f408d9013e82126253981009571d1c9b21f6f4d4da12559b15c2e
|
|
BLAKE2b-256 checksum How to use checksums |
0ca4f1f864376b415e48093b8a2d40379e1229684b5bcc83aa105bb1d35f2e7e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.8 CPython/2.7.10
|
Release files / environize-0.0.1-py3-none-any.whl
| Download URL | environize-0.0.1-py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
41e1f23d5f9b7f8253354f544d7b76400ff7b7751eb6cb71b2523537b453ea0b
|
|
BLAKE2b-256 checksum How to use checksums |
a395820effc5f174c9ddf45c762c45a48038ef61d54e0e1b1fa7c6aa7d53f22f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.8 CPython/2.7.10
|
Security for environize 0.0.1
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.